Q:

Search for and print only matched pattern

I have some huge xml text files.  I need to write a script to find and print a specific tag only.  I tried sed and grep but they both return the whole line.
Using SunOS 5.x, so not all linux commands may work.  grep -o is not available.
The 'xml' file is not actually one huge xml document, but each line is a separate xml document, with just a few tags, not even nested.  And the structure is fairly easy, so full xml parsers is not needed, and probably would not work.  
I was looking for sed, awk, or some other one liners, but could not get them to work, and they are both relatively new to me.

A:

You should use a tool that's made for parsing XML files, however here is an example of how you might do that in sed:
Given a simple line like <foo>bar</foo><baz>qux</baz> and you want the value "bar" you can do this:
sed -e 's|.*<foo>\([^<]*\)</foo>.*|\1|' inputfile

