0

I have a string like this.

30: sometext 57: sometext ....

I want to iterate over the numbers that come before the colon inside a shell script.

2
  • 3
    What is your expected output for the above string and what did you try?
    – Inian
    Commented Oct 6, 2016 at 11:41
  • give this a try: grep -oP '\d+(?=:)' <<< $yourString
    – Kent
    Commented Oct 6, 2016 at 11:43

1 Answer 1

1

With egrep - Vertical Output

echo "30: sometext 57: sometext" | egrep -o '[0-9][0-9]'
30
57

With awk - Horizontal Output

echo "30: sometext 57: sometext"|awk -F'["|:| ]' '{print $1, $(NF-2)}'
30 57

Not the answer you're looking for? Browse other questions tagged or ask your own question.