Using awk on the Command Line to Parse Files


I needed to format a file that contained a list of words with their accompanying definitions.  I didn't need the definitions and wanted to put an 'item' tag around each word.  awk to the rescue!

The Command:

awk '{print ""$1""}' < words.xml

I have this stored in the words.xml file:


BAD something bad
BAG to put into a bag
BAH intj. expressing disgust
BAL type of shoe (balmoral)
BAM to strike with a dull sound
BAN to prohibit/Rumanian coin

After running the command, I get:

<item>BAD</item>
<item>BAG</item>
<item>BAH</item>
<item>BAL</item>
<item>BAM</item>
<item>BAN</item>

Thanks awk!