On 02/13/2012 08:27 AM, Per Jessen wrote:
lynn wrote:
I'm regex'd out of it at the moment. Given a string like this:
lynn:*:3000002some other stuff100hellolynn:
Is there a way to get the 3000002 into a variable v1 and the 100 into a variable v2? bash? Any recommended starting point? Assuming you've got a file with such lines, this might get you started:
sed -r -e 's/^[^0-9]*([0-9]+)[^0-9]+([0-9]+).*$/\1 \2/' file
Hi Thanks for the input everyone. It's helped me get started. I should have been more specific. I've narrowed down the task to getting just the first number in a string _but_ the output comes from the wbinfo command e.g. wbinfo -i lynn CACTUS\lynn:*:3000002:100::/home/CACTUS/lynn2:/bin/bash I want to extract the 3000002 I've narrowed it down to this: #!/bin/bash str=$(wbinfo -i $1) echo $str | sed -r 's/^([^.]+).*$/\1/; s/^[^0-9]*([0-9]+).*$/\1/' which gives 3000004. Good. But if the user is called lynn2, it gives 2 So the problem comes down to: how to get the first number in the string _after_ the *: sequence (This would work for wbinfo --group-info too as it is the same format) Thanks, L x -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org To contact the owner, e-mail: opensuse+owner@opensuse.org