LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 01-24-2011, 09:15 PM   #1
chuikingman
Member
 
Registered: Aug 2009
Posts: 86

Rep: Reputation: 16
echo two command output in the same line


Hi,
I try to write script and echo two command at the same line .
echo "A"
echo "B"

How can I pipe above two command at the same line in text file .
So, in the output text file , you can see below ???
Code:
A     B
not
Code:
A
B
Any sugggestion ???
 
Old 01-24-2011, 09:21 PM   #2
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 248Reputation: 248Reputation: 248
Greetingz!

A dirty lil hack like
Code:
printf "`command 1` `command 2`\n"
will do it in most shells.
 
Old 01-24-2011, 09:28 PM   #3
chuikingman
Member
 
Registered: Aug 2009
Posts: 86

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by xeleema View Post
Greetingz!

A dirty lil hack like
Code:
printf "`command 1` `command 2`\n"
will do it in most shells.
I try
[code]
[root@TST ~]# printf " ' echo A ' ' echo B ' \n "
' echo A ' ' echo B '
[root@TST ~]# echo A
A
[\code]

Is it not the one I want ... the command is printout , not execute ??
Any suggestion ??
 
Old 01-24-2011, 09:33 PM   #4
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,109

Rep: Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102
Hi,

another (but also dirty) way
Code:
(echo A;echo B)|tr '\n' '\t'
Evo2.
 
Old 01-24-2011, 09:33 PM   #5
chuikingman
Member
 
Registered: Aug 2009
Posts: 86

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by xeleema View Post
Greetingz!

A dirty lil hack like
Code:
printf "`command 1` `command 2`\n"
will do it in most shells.
I try , but it is not work for ps command :
Code:
[root@TST ~]# printf " `echo A` `echo B` \n"
 A B
[root@TST ~]# printf " `echo date ` `ps -o %cpu,%mem,lstart,args,comm,cputime,pid,rss,vsz -p 1` \n"
-bash: printf: `C': invalid format character
 date [root@TST ~]# printf " `echo A` `ps -o %cpu,%mem,lstart,args,comm,cputime,pid,rss,vsz -p 1` \n"
-bash: printf: `C': invalid format character
 A [root@TST ~]#
Any suggestion ??
 
Old 01-24-2011, 09:43 PM   #6
evo2
Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Debian, SL
Posts: 5,109

Rep: Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102Reputation: 1102
printf is trying to interpret the "%" chars. You might be able to escape them like "%%".

Evo2.
 
Old 01-24-2011, 09:47 PM   #7
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
How about
Code:
echo -n "A ";echo B
 
Old 01-24-2011, 10:09 PM   #8
xeleema
Member
 
Registered: Aug 2005
Location: D.i.t.h.o, Texas
Distribution: Slackware 13.x, rhel3/5, Solaris 8-10(sparc), HP-UX 11.x (pa-risc)
Posts: 987
Blog Entries: 4

Rep: Reputation: 248Reputation: 248Reputation: 248
@chuikingman

That lil printf trick I was talking about assumes your commands output just one line of text.
Something with multi-line output (like "ps") is going to have very...different results.

What two commands are you using? Can you provide the output from both, and an example of the output you want?
 
Old 03-31-2011, 06:20 PM   #9
zeppelinrox
LQ Newbie
 
Registered: Mar 2011
Posts: 1

Rep: Reputation: 0
Thumbs up

Quote:
Originally Posted by crts View Post
How about
Code:
echo -n "A ";echo B
How about... AWESOME!

I'm working on gscripts for my milestone (minfree tweaks and launcher priority stuff) and wanted to check instantly the effects with another gscript.

This works like a charm:
Code:
echo -n "Home Launcher Priority is: ";getprop ro.HOME_APP_ADJ
Output is:
Quote:
Home Launcher Priority is: 0
 
  


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
grep | xargs -I echo $(foo; bar; echo $(fee; fi; fo; fum)) == questionable output.. GrapefruiTgirl Programming 11 12-07-2010 07:02 PM
Command Line Expansion & echo Merrida Fedora 4 05-26-2009 12:30 AM
Bash Script, no new line for echo command jorisb Linux - General 5 11-05-2005 12:08 AM
Redirecting output to a command-line argument of another command madiyaan Linux - Newbie 1 02-19-2005 04:35 PM
Command to output file content line by line aznluvsmc Programming 2 09-12-2004 07:45 PM


All times are GMT -5. The time now is 10:00 PM.

Main Menu
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