Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SED Insert & Append lines in a script

Status
Not open for further replies.

gxh1000

Programmer
Aug 4, 1999
10
US
I have a file that I am manipulating in a Unix script. I want to use a sed command to insert text before the 1st line:

DATE $TDYSDATE //where $TDYSDATE is a variable set in
the script.

And I want to append text after the last line:

ENDOFFILE

This is what I've tried and it doesn't work:

#!/bin/ksh
cat test_file | sed '1i\DATE $TDYSDATE' \
'$a\ENDOFFILE' > new_file

I've tried numerous variations of this and I keep getting the same error - "Extra Text At End Of Command"

Please help.

 
You may try something like this:
(echo "DATE $TDYSDATE";cat test_file;echo "ENDOFFILE")>new_file
But if you insist on sed:
sed "1i\
DATE $TDYSDATE
"';$a\
ENDOFFILE
' test_file > new_file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
None of the sed proposals work, but the echo suggestion does. So, echo it is. PHV, thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top