inserting lines

Hi
I would like to add lines to a file at specific locations.

eg: If I have a file containing data...

ABC
DEF
GHIJKLKMNOP
RSTUVWXYZ

and I have a requirement to insert a lines

a) "LINE_FIRST" before first line in the file
b) "LINE_X" before third line in the file
c) "LINE_LAST" after last line in the file

The result file should look like this

LINE_FIRST
ABC
DEF
LINE_X
GHIJKLKMNOP
RSTUVWXYZ
LINE_LAST

Any ideas how I could do this.

Thanks for the help

If you have a file that contains specific data that you want to insert lines before after then use the first example. If you want things inserted at specific lines then use the second example.

sed -e '/^ABC/s/^/LINE_FIRST\n/' -e '/^DEF/s/$/\nLINE_X/' -e '/^RSTUVWXYZ/s/$/\n
LINE_LAST/' test

echo ==============

sed -e '1,1s/^/LINE_FIRST\n/' -e '2,2s/$/\nLINE_X/' -e '$s/$/\nLINE_LAST/' test
awk 'NR==1{print "word1 "$0;next}NR==3{print "word2 "$0;next}END{print $0" word"}1' file