LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 07-21-2010, 04:18 AM   #1
elainelaw
Member
 
Registered: Jan 2008
Posts: 258

Rep: Reputation: 30
Change echo output


I have the below command

echo "test1" > /tmp/file
echo "test2" >> /tmp/file

The output of /tmp/file is

test1
test2

If I want the output is in same line as below , can advise what can i do ? thx

test1 test2
 
Old 07-21-2010, 04:57 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
http://tldp.org/LDP/Bash-Beginners-G...html#tab_08_01
 
Old 07-21-2010, 05:02 AM   #3
karthiksharu
LQ Newbie
 
Registered: May 2009
Posts: 15

Rep: Reputation: 0
Quote:
Originally Posted by chrism01 View Post

ya ..Chris is correct ..

printf "test1" > /tmp/file
printf "test2" >> /tmp/file
 
Old 07-21-2010, 05:08 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,362

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Actually, I'm pointing at the escape codes for 'echo' ; specifically \c means don't print a newline.
 
Old 07-21-2010, 07:14 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
You should use the "-n" option for echo, which tells it not to stick a newline on the end.
 
  


Reply



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
When I use xargs with echo, why does the output contain an extra space? web_janitor Linux - General 2 08-20-2009 04:18 PM
change echo default setting to -e in Etch fangorn Debian 1 03-13-2007 09:42 AM
How to change listening port of echo server [RH9]? immer Linux - Networking 5 11-29-2003 04:30 PM
Using echo to output a string to a file with forward slashs chrisk5527 Linux - General 15 06-21-2003 02:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:35 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
Open Source Consulting | Domain Registration