simple pattern match with awk, sed
I have a line with the following pattern:
some text (x, y) where x y are the numbers I am looking for a simple awk or sed or bash script that would print out just x and y thanks |
depends how strict the formatting is but this should work...
$ echo "some text (123, 456)" | sed -e "s/^.*(\([0-9]*\),\ \([0-9]*\)).*$/\1 \2/" 123 456 Can anyone tell *me* though, why it doesn't work if any of the *'s are replaced with +'s? * = 0 or more, + = 1 or more, so i'm clearly missing something, and have done for a long long time... |
IIRC, a bare + is not special to sed, you need to escape it.
|
If you want sed to accept + you need to use the -r switch.
Cheers, Tink |
running the command above = simply running echo. Am i missing something?
|
Code:
echo "some text (123, 456)" | sed -e "s/^.*(\([0-9]*\),\ \([0-9]*\)).*$/\1 \2/" actually look like? Cheers, Tink |
*blink*
-r extended regex Where the frell did that come from? I never noticed that before. I'm using Slack 10.2 here (too lazy to upgrade) and I just noticed I have it here, probably been there for years. Gah, what sneaks past my myopia, gets shot down by my attention deficit disorder. |
no, i tried exactly the same line
prints 'some text (123, 456)' |
ok ,fixed it.... space missing.. thanx a lot
|
Btw, depending on your input, you might want to use no printing mode, so lines that don't match will be ignored. Give sed the -n option and whack a p after the final delimiter,
Code:
whatever... | sed -n 's/...../\1 \2/p' This also makes it easy to see if your pattern is working, because sed gives you no output at all if it doesn't match, rather than simply echoing the input. |
cool.. thanx!
|
All times are GMT -5. The time now is 08:50 PM. |