LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices



Reply
 
Search this Thread
Old 02-18-2004, 06:00 AM   #1
synapse
Member
 
Registered: Jan 2004
Location: On Planet Earth.
Distribution: Slackware 12
Posts: 244

Rep: Reputation: 30
shell scripting (special characters)


Hi

How do i go about passing a special character to a command.

Eg i have a file with a line of text within it called names.txt, If i send
#echo "this is a new line of text" >>names.txt

Then look into the file i will see

Johnthis is a new line of text

This appends to existing data in the file , I want to tell the redirector to insert a new line before appending so that the output becomes

John
this is a new line of text

Are there any special characters like \n or something that i can pass to do this.

Thanx
 
Old 02-18-2004, 06:19 AM   #2
guygriffiths
Member
 
Registered: Jun 2003
Location: Reading, UK
Distribution: Debian 3.0, LFS
Posts: 524

Rep: Reputation: 35
This will work:

cat >> names.txt << EOF
this is a new line of text
as is this
so is this one
EOF

You could also use:

echo -e "\nthis is a new line of text" >> names.txt

The -e flag allows special characters to be used. Have a look at "man echo".
However, when I use the example you gave it inserts a newline character at the end anyway, and Linux text files normally end with a newline anyway, so if you build the file from scratch using echo commands it shouldn't be a problem.
Hope this helps
Guy
 
Old 02-18-2004, 06:21 AM   #3
codeape
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 62

Rep: Reputation: 15
# echo -e "\nthis is a new line of text"

note: Echo will automatically insert a new-line at the *end* of the string so:

# touch names.txt
# echo Harry >>names.txt
# echo John >>names.txt
# echo Bill >>names.txt
#
# more names.txt
Harry
John
Bill

Check the manpages for 'echo' or 'printf' for more info.

Last edited by codeape; 02-18-2004 at 06:23 AM.
 
Old 02-18-2004, 06:22 AM   #4
codeape
Member
 
Registered: Feb 2004
Distribution: Debian
Posts: 62

Rep: Reputation: 15
Note to self: Type faster.
 
Old 02-18-2004, 07:05 AM   #5
synapse
Member
 
Registered: Jan 2004
Location: On Planet Earth.
Distribution: Slackware 12
Posts: 244

Original Poster
Rep: Reputation: 30
Thanx for the help

cheers
 
  


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
Special characters problem MartinZ Suse/Novell 5 07-12-2011 10:21 PM
Special Characters SimeonV Suse/Novell 14 07-07-2006 02:29 PM
special characters greenbox Linux - Software 9 12-23-2005 08:33 PM
Special characters consty Programming 3 08-07-2005 06:53 AM
using special characters one_ro Mandriva 5 11-04-2004 09:52 AM


All times are GMT -5. The time now is 08:12 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration