Howto print text between tags or characters with awk or sed
Submitted by tom on 28. April 2009 - 21:52Took me a while to figure out this one. All I wanted to do is to print the text between two tags/characters/strings.
The IMHO nicer Awk way:
$ echo "bla(foo)"|awk -F'[(|)]' '{print $2}' foo
$ echo "bla=@@foo@@"|awk -F'[@@|@@]' '{print $3}' foo
and with sed:
$ echo "blah(foo)"|sed -n 's/.*(\([^ ]*\))/\1/p' foo
echo "aaafoobbb"|sed -n 's/.*aaa\([^ ]*\)bbb/\1/p' foo
Figured.