adding a line to a file | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

adding a line to a file

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 03-26-2007
andy2000 andy2000 is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 28 August 2010, 5:30 AM EDT
Posts: 43
Thanks: 1
Thanked 0 Times in 0 Posts
adding a line to a file

I want to add a line at the beginning and at the end of a file..

e.g.

echo "at the beginning.." > tmp_file &&
cat file >> tmp_file &&
echo "last line" >> tmp_file &&
mv tmp_file file

is there a nice way for doing that??

Thx
Sponsored Links
    #2  
Old 03-26-2007
dennis.jacob's Avatar
dennis.jacob dennis.jacob is offline Forum Advisor  
Registered User
 
Join Date: Feb 2007
Last Activity: 30 March 2014, 9:33 AM EDT
Location: Singapore/Cochin
Posts: 871
Thanks: 0
Thanked 12 Times in 11 Posts
What about this..?

Code:
echo -e  "Before the data\n $(cat file)\nEnd of data"

Sponsored Links
    #3  
Old 03-26-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 7 November 2013, 6:42 AM EST
Posts: 2,651
Thanks: 0
Thanked 17 Times in 17 Posts
to add a line at beginning of file

Code:
sed '1 i this is first line' file

to add at end of file

Code:
sed '$ a this is last line' file

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
help with sed adding line to end of file bjhum33 Shell Programming and Scripting 3 02-24-2012 03:11 AM
adding a line to a text file LMHmedchem Shell Programming and Scripting 3 06-11-2011 02:40 AM
adding a line to file 76455 Shell Programming and Scripting 8 09-05-2010 04:59 PM
Adding a line to a file mwrg Shell Programming and Scripting 12 12-24-2009 10:24 AM
Adding new line at the end of file somesh_p Shell Programming and Scripting 5 11-05-2007 04:47 PM



All times are GMT -4. The time now is 06:54 PM.