LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-25-2009, 06:04 AM   #1
windstory
Member
 
Registered: Nov 2008
Posts: 486

Rep: Reputation: 36
can add a text line to text files?


can add a text line to text files?

As an example, I have learned the under-mentioned code.

Code:
echo '/opt/lampp/lampp start'  > /etc/rc.d/rc.local
But this caused only one line as the above-mentioned ceode at the file.
So, I should edit ever text files.

Is it possible to add a text line to a text file?
And one more, also is it possible to add a text line to some line of a text file?
 
Old 08-25-2009, 06:07 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
The double >> means "append at the end of the file", so that the original content of the file is preserved.
Code:
echo '/opt/lampp/lampp start'  >> /etc/rc.d/rc.local
Not sure about your last question, but maybe it is a task for sed. Please, do an example of what do you want to achieve (input and desired output are welcome).
 
Old 08-25-2009, 06:08 AM   #3
Nylex
LQ Addict
 
Registered: Jul 2003
Location: London, UK
Distribution: Slackware
Posts: 7,464

Rep: Reputation: Disabled
You want to use >> to append text to a file, i.e.
echo "/opt/lampp/lampp.start" >> /etc/rc.d/rc.local

This will append the text "/opt/lampp/lampp.start" to /etc/rc.d/rc.local. It will be on a new line if the last character in the file was a newline character (before the append, obviously).
 
Old 08-25-2009, 06:13 AM   #4
Matz
Member
 
Registered: Oct 2006
Distribution: Kubuntu 9.04, Debian Etch
Posts: 178

Rep: Reputation: 31
try this:
Code:
echo '/opt/lampp/lampp start'  >> /etc/rc.d/rc.local

use ">>" to append the new line to the existing text file. If you want to append this in a new line of rc.local then you should do this
Code:
echo -e '/n/opt/lampp/lampp start'  >> /etc/rc.d/rc.local
Hope it helps
 
Old 08-25-2009, 07:40 AM   #5
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
colucix, Nylex, Matz/ Many thanks for your kind replies.

Quote:
echo '/opt/lampp/lampp start' >> /etc/rc.d/rc.local
echo -e '/n/opt/lampp/lampp start' >> /etc/rc.d/rc.local
These two codes works fine!
 
  


Reply


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Sed append text to end of line if line contains specific text? How can this be done? helptonewbie Linux - Newbie 4 10-23-2013 02:48 PM
add text to end of line? tatoosh Linux - Newbie 8 07-31-2009 04:28 AM
Bash: How to add a line on top of text files guest Programming 12 02-07-2009 07:23 AM
How to add a text to first line of a text file? oskeewow Linux - Newbie 6 04-23-2008 01:40 PM


All times are GMT -5. The time now is 10:17 AM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration