LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 08-18-2009, 10:57 PM   #1
Siljrath
Member
 
Registered: Nov 2004
Location: the internet
Distribution: sid, slack, gentoo, witch, bedrock, etc
Posts: 152

Rep: Reputation: 36
[solved] add more than one line to end of file


right... tether's end. searched thru lq and other forums and that well known search engine for some time, as i cant possibly be the first person ever to need to know how to do this. i can only presume i'm searching the wrong terms, or the terms im searching are just too common to find what im looking for specifically. time to ask.

i'm seeking to add multiple lines to the end of a file
and/or make a file with a number of predefined lines of text already in it
in a bash script.

i'd really rather not have to keep on doing echo addingthislineoftext >> tothisfile && echo addingthislineoftext >> tothisfile && echo addingthislineoftext >> tothisfile && echo addingthislineoftext >> tothisfile && etc. for the hundreds of unique lines i need to add, and would prefer to keep the text in the bash script, as a solid block of text as is to be found in the resulting file it's to be output to (to keep it easy to edit later incase i want to).

so basically, my question is, how can i add, via my bash script, a block of text (contained in the bash script preferably) to the end of a file?

any experienced bashers reading this with a suggestion?

Last edited by Siljrath; 11-23-2010 at 11:11 PM.
 
Old 08-18-2009, 11:01 PM   #2
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Use a HERE document in your script.

cat >>${1) <<EOF
This are the lines
to add
to the end of the file
EOF
 
  


Reply

Tags
bash, here


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
add text to end of line? tatoosh Linux - Newbie 8 07-31-2009 03:28 AM
End-of-line Characters missing from last line of md5 file. Md5sum fails mehorter Linux - General 5 06-29-2009 08:56 PM
C: fread to read a file line by line until the end Blue_muppet Programming 2 09-19-2008 09:42 AM
Shell scripting: How to add characters at the end of the line Micro420 Programming 7 05-18-2007 01:56 AM


All times are GMT -5. The time now is 02:05 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration