find word between string
Hello all,
I did a search before I posted but did not find what I needed. I am looking to write a sed/awk/cut/tr command that will parse and print out numbers between two unique strings. for instance number=3243423 random text blah blah yes no number=323432432 fsd jklf sjl number=32432432 basically I have to grab the number after the = sign after every "number=" string without knowing how long the number will be. Can somebody give some suggestions on how to do this? I read that you can use sed -n '/FOO/,/BAR/p' test.txt but that only works if it is only one line.... and it is inclusive..any help would be great. thank you! |
Code:
string="number=3243423 random text blah blah yes no number=323432432 fsd jklf sjl number=32432432" |
Oops, be careful...
Code:
string="number=3243423 random text blah blah yes no number= fsd jklf sjl number=32432432" |
great!! thanks for the help. i think this will solve my problem.
|
Quote:
Code:
echo $string | egrep -o "number=[0-9]+" |
It is this both the silly length, and duplication requirement, of the [ ] character classes vs. pcres' \d+, etc. that encourages me to avoid sed/awk much of the time.
|
later version of sed (-r switch) and gawk have options for extended regular expressions, but not sure about pcre though
|
Not mine on NetBSD. I'll have to update my /usr/local copy. Thanks, I wasn't aware of that.
|
no problem.
|
All times are GMT -5. The time now is 06:57 AM. |