LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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, 01:23 AM   #1
ust
Senior Member
 
Registered: Mar 2003
Location: fasdf
Distribution: Debian / Suse /RHEL
Posts: 1,130

Rep: Reputation: 30
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, 02:02 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
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, 02:14 AM   #3
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,063

Rep: Reputation: 381Reputation: 381Reputation: 381Reputation: 381
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 02:15 AM.
 
  


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


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