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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert BLANK lines into a file with sed or echo?

Status
Not open for further replies.

linmatt

Technical User
May 22, 2002
50
GB
I'm about to hit a wall very hard. I don't do as much scripting as I'd like and so am a bit rusty.

I need to add 4 lines into the begining of a file. The first contains just 'H' and the date as a header line, the next 3 are blank. This is required for import into a database. On the net all I can find is how to delete them! The rest of the script is ready to roch and roll, just this bit missing.

Please can someone help...
 
Before you start filling the file with your data 'proper', issue 4 commands like so:

echo H `date` > filename
echo >> filename
echo >> filename
echo >> filename

That should give you the header and the three blank lines. If I've misinterpreted, please post back. Cheers.
 
Thanks Ken

I'd just discovered that, believe it ot not. Why doesn't the man page of any web site show you actual examples?

Thanks again
 
For sed folks, you could do

sed '
1{
i
}' < filename

or

sed '1{H;x;s/^\n/&&&&/;}' < filename Cheers,
ND [smile]

bigoldbulldog@hotmail.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top