The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
file command rprajendran UNIX for Advanced & Expert Users 3 05-13-2008 10:45 AM
rm command not able to remove file jambesh Shell Programming and Scripting 7 12-21-2007 04:37 AM
VI command for File Please $Circle$ UNIX for Dummies Questions & Answers 12 09-05-2005 01:23 AM
End of file using more command Enda Martin UNIX for Dummies Questions & Answers 3 06-18-2001 07:49 AM
for file in ???? - command tamer UNIX for Dummies Questions & Answers 10 01-31-2001 06:40 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 11-09-2005
whatisthis's Avatar
Registered User
 

Join Date: Aug 2004
Posts: 175
What is the command to add heading to a file?

Hi,
I'd like to add one line to the top of my file.
I know there is a command to be able to do it.
But I forgot ......



Please help if you can ....
Reply With Quote
Forum Sponsor
  #2  
Old 11-09-2005
Registered User
 

Join Date: Oct 2005
Posts: 9
I don't know a specific command, but this one liner works fine in sh, bash, and tcsh (a bunch of other shells too):

Code:
( echo "Line to add" ; cat targetfile ) > tempfile ; cat tempfile > targetfile ; rm -f tempfile
Where targetfile is the file you're trying to add one line to.
Reply With Quote
  #3  
Old 11-09-2005
zazzybob's Avatar
Registered Geek
 

Join Date: Dec 2003
Location: Melbourne, Australia
Posts: 2,100
Code:
sed '1 i\
Line to insert here' infile > outfile
Press Enter after the \ and then continue on the next line, exactly as indicated above.

Cheers
ZB
Reply With Quote
  #4  
Old 12-02-2005
npn npn is offline
Registered User
 

Join Date: Nov 2005
Posts: 14
Arrow adding Data in First line

existing file filename "file_one.dat"

which contains
AMITH
ARUN
ARVIND

I am adding "I LOVE PIZZA" in the first line of this file

Here it is:
echo "I LOVE PIZZA" | cat > tempfile ; cat file_one.dat >> tempfile ; mv tempfile file_one.dat

Result:
I LOVE PIZZA
AMITH
ARUN
ARVIND
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 12:53 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0