The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 02:45 PM
rm command not able to remove file jambesh Shell Programming and Scripting 7 12-21-2007 07:37 AM
VI command for File Please $Circle$ UNIX for Dummies Questions & Answers 12 09-05-2005 05:23 AM
End of file using more command Enda Martin UNIX for Dummies Questions & Answers 3 06-18-2001 11:49 AM
for file in ???? - command tamer UNIX for Dummies Questions & Answers 10 01-31-2001 09:40 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-09-2005
whatisthis's Avatar
whatisthis whatisthis is offline
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 ....
  #2 (permalink)  
Old 11-09-2005
flyingpenguin flyingpenguin is offline
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.
  #3 (permalink)  
Old 11-09-2005
zazzybob's Avatar
zazzybob zazzybob is offline Forum Advisor  
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
  #4 (permalink)  
Old 12-02-2005
npn npn is offline
Registered User
  
 

Join Date: Dec 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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:26 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0