LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   can add a text line to text files? (https://www.linuxquestions.org/questions/linux-newbie-8/can-add-a-text-line-to-text-files-750067/)

windstory 08-25-2009 05:04 AM

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?

colucix 08-25-2009 05:07 AM

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).

Nylex 08-25-2009 05:08 AM

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).

Matz 08-25-2009 05:13 AM

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

windstory 08-25-2009 06:40 AM

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!


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