> add text to end of text file | Unix Linux Forums | Shell Programming and Scripting

  Unix/Linux Go Back    


Shell Programming and Scripting Unix shell scripting - KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and shell scripts and shell scripting languages here.

add text to end of text file

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 05-31-2007
leeRoberts2007 leeRoberts2007 is offline
Registered User
 
Join Date: May 2007
Last Activity: 1 June 2007, 2:02 PM EDT
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts
add text to end of text file

Hi,

I assume there is a simple solution, but as usual i can't find it!
How can i add a line of text to the end of a text file on a new line?

i.e
file.txt
________________
this is my text file
________________

file.txt
________________
this is my text file
WITH A NEW LINE
________________

Thanks for your time

Lee
The Following User Says Thank You to leeRoberts2007 For This Useful Post:
ailton.biji (05-23-2014)
Sponsored Links
    #2  
Old Unix and Linux 05-31-2007
Shell_Life's Unix or Linux Image
Shell_Life Shell_Life is offline
Registered User
 
Join Date: Mar 2007
Last Activity: 21 June 2012, 3:19 PM EDT
Location: Bahia, Brazil
Posts: 1,203
Thanks: 1
Thanked 103 Times in 100 Posts
LeeRoberts,
Here is one way of doing this:

Code:
(cat input_file ; echo "WITH A NEW LINE") > output_file

The Following User Says Thank You to Shell_Life For This Useful Post:
ailton.biji (05-23-2014)
Sponsored Links
    #3  
Old Unix and Linux 05-31-2007
reborg's Unix or Linux Image
reborg reborg is offline Forum Advisor  
Administrator Emeritus
 
Join Date: Mar 2005
Last Activity: 29 March 2012, 7:00 PM EDT
Location: Ireland
Posts: 4,464
Thanks: 0
Thanked 12 Times in 11 Posts

Code:
echo "WITH A NEW LINE" >> file

The Following User Says Thank You to reborg For This Useful Post:
ailton.biji (05-23-2014)
    #4  
Old Unix and Linux 05-31-2007
leeRoberts2007 leeRoberts2007 is offline
Registered User
 
Join Date: May 2007
Last Activity: 1 June 2007, 2:02 PM EDT
Posts: 4
Thanks: 0
Thanked 2 Times in 2 Posts
thanks, and how about something at the start of a text file?
The Following User Says Thank You to leeRoberts2007 For This Useful Post:
ailton.biji (05-23-2014)
Sponsored Links
    #5  
Old Unix and Linux 05-31-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts

Code:
sed '1i yourline' file

The Following User Says Thank You to ghostdog74 For This Useful Post:
ailton.biji (05-23-2014)
Sponsored Links
    #6  
Old Unix and Linux 05-31-2007
lorcan lorcan is offline
Registered User
 
Join Date: May 2007
Last Activity: 13 August 2012, 12:14 AM EDT
Posts: 224
Thanks: 0
Thanked 2 Times in 2 Posts
Another method


Code:
cat file | awk ‘BEGIN {print “This is my first line”} {print $0}’ > file

Sponsored Links
    #7  
Old Unix and Linux 05-31-2007
ghostdog74 ghostdog74 is offline
Registered User
 
Join Date: Sep 2006
Last Activity: 28 January 2015, 8:30 AM EST
Posts: 2,669
Thanks: 0
Thanked 18 Times in 18 Posts
Quote:
Originally Posted by lorcan
Code:
cat file | awk ‘BEGIN {print “This is my first line”} {print $0}’ > file

UUOC

Code:
awk 'BEGIN {print "This is my first line"}{print $0}' file > file3322

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Script to create a text file whose content is the text of another files tenteyu Shell Programming and Scripting 1 03-22-2012 09:05 PM
Converting a text file with irregular spacing into a space delimited text file? evelibertine UNIX for Dummies Questions & Answers 5 09-05-2011 11:47 AM
[bash help]Adding multiple lines of text into a specific spot into a text file cdn_humbucker Shell Programming and Scripting 2 03-06-2010 02:11 AM
Adding specific text and spaces to each line in a text file hertingm Shell Programming and Scripting 4 08-25-2008 02:34 PM
grep multiple text files in folder into 1 text file? coppertone UNIX for Dummies Questions & Answers 7 08-23-2002 02:50 PM



All times are GMT -4. The time now is 04:22 PM.