David Wright
David Wright

Reputation: 21

Extracting the numbers only from string using sed

I have this string Time: 4 days (361440 seconds) and trying to extract only the number 361440 from this. I have gotten so far as to extract 361440 seconds using sed "s/.*(\(.*\))/\1/" I keep going round in circles trying to just get the number from it.

Thanks

Upvotes: 0

Views: 52

Answers (1)

Kent
Kent

Reputation: 195029

You didn't explain the rule of extraction very clearly. Just based on your sed codes, this grep line should work for your example:

grep -oP '\(\K\d+'

Ok, then extend your sed one-liner a bit:

sed 's/.*(\([0-9]\+\).*/\1/'

Upvotes: 1

Related Questions