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 09-11-2008, 12:23 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 31
output format


I have a script "my_script" to echo file to it as below,

$vi my_script
echo "abc" > file
echo "def" > file

The output is as below
===============
abc
def

Now I want the output as below , there are 5 space between the word "abc" and "def" , can advise what can i do ? thx

I want the output as below
==================
$vi file
abc def
 
Old 09-11-2008, 01:02 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Your first output is wrong, using '>' will overwrite. You'd have to use '>>' to append a new line.
To append with spaces on the same line use

Code:
echo -n "   def" >> file
 
Old 09-11-2008, 01:14 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 405Reputation: 405Reputation: 405Reputation: 405Reputation: 405
Quote:
Originally Posted by ust View Post
I have a script "my_script" to echo file to it as below,

$vi my_script
echo "abc" > file
echo "def" > file

The output is as below
===============
abc
def
No, this will result in a file which will contain "def". As the previous poster said, each time you use > the file is reinitialized, unless you use >> instead, to append.

Quote:
Now I want the output as below , there are 5 space between the word "abc" and "def" , can advise what can i do ? thx

I want the output as below
==================
$vi file
abc def
[/quote]

Quote the strings adequately.

Code:
echo "abc     def" > myfile
You can as well use cat << EOF to put whole blocks of text

Code:
cat << EOF
this
is my
custom tale
EOF > myfile

Last edited by i92guboj; 09-11-2008 at 01:15 AM.
 
  


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
change output format for df baddah Programming 3 04-21-2008 08:08 AM
Format bash output ceashton Programming 3 08-17-2007 12:16 PM
last command output format bujecas Linux - General 1 10-12-2006 09:54 AM
i need rpm output in table format Uday123 Fedora 1 12-17-2005 05:15 PM
C++ format float number output keefaz Programming 3 06-06-2004 02:16 PM

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

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