LinuxQuestions.org
Help answer threads with 0 replies.
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 01-19-2004, 09:19 AM   #1
Beuzekom
Member
 
Registered: Aug 2003
Location: Netherlands
Distribution: Redhat 9.0
Posts: 38

Rep: Reputation: 15
Question Cat ...


Hi,

I am looking for a way to add some text to a text file. This should be done automatically via a shell command.

E.g. I have a file CONFIG.TXT and I want to add the text "configparameter=83321;"

How can I do this from the linux shell via CLI commands?

Probably a very basic questions for the most of you but I dunno...

Thanks !
 
Old 01-19-2004, 09:23 AM   #2
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
echo "Whatever you want to append to the file" >> /etc/config.file

If you use a single ">" character you will overwrite the target file. The double ones (">>") will append the line inside the quotes to the end of the file.


Håkan
 
Old 01-19-2004, 09:33 AM   #3
Beuzekom
Member
 
Registered: Aug 2003
Location: Netherlands
Distribution: Redhat 9.0
Posts: 38

Original Poster
Rep: Reputation: 15
Aaagh right the echo command ...... thanks!

How are special characters treated ... like e.g. if you want to add the > character as well
 
Old 01-19-2004, 09:42 AM   #4
Beuzekom
Member
 
Registered: Aug 2003
Location: Netherlands
Distribution: Redhat 9.0
Posts: 38

Original Poster
Rep: Reputation: 15
Never mind .. normally this is a / but it seems not to work within our software
(our problem ....)

Thanks Håkan
 
Old 01-19-2004, 06:32 PM   #5
hw-tph
Senior Member
 
Registered: Sep 2003
Location: Sweden
Distribution: Debian
Posts: 3,032

Rep: Reputation: 58
The use of hard quotes (single quotes) lets everything inside the quotes pass as part of the string. You can enclose double quotes inside hard quotes and even shell variable names - they won't be interpreted inside single quotes. The ">" character will just be another character inside single quotes.

echo 'Single quotes are "hard" quotes!' >> 000.test
echo '< and > are tricky characters - I do not even know their names' >> 000.test
echo '...we can even pass $SHELL variable names.' >> 000.test


With double quotes, environment/shell variables such as $SHELL will be interpreted and the value of the variable will be printed instead of $SHELL.

echo "My favourite shell is $SHELL" >> 000.test
...will append the line "My favourite shell is /bin/bash" as I use bash.


Håkan

Last edited by hw-tph; 01-19-2004 at 06:35 PM.
 
  


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
less, cat, sed or what ebasi Linux - Software 8 07-28-2004 04:26 AM
My Cat unimaginative General 71 02-18-2004 02:08 PM
Any cat gurus in here? deepsix Linux - General 14 08-28-2003 10:41 AM
cat notsoevil Linux From Scratch 3 02-14-2002 11:16 AM
regarding cat gui10 Linux - Security 6 12-07-2001 09:09 PM


All times are GMT -5. The time now is 05:59 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