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 11-08-2012, 11:05 PM   #1
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Rep: Reputation: Disabled
pipe and paste


Hi I want to combine the output of two commands in this form

awk 'Complex command' file1 | awk ' Different complex command' file2

but i want the ouptuts on the same line

another option might be
awk 'Complex command' file1 | paste < (` awk ' Different complex command' file2`)
but neither is working

any ideas ?
Thanks
 
Old 11-08-2012, 11:46 PM   #2
replica9000
Member
 
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', FreeBSD, Android
Posts: 642
Blog Entries: 2

Rep: Reputation: 112Reputation: 112
Well it depends what 'Complex command' is. Is 'file2' a result of processing 'file1'?

Maybe something like this might be what you want?
cat 'file1' | awk 'Complex command' | awk ' Different complex command' > 'file2'
 
Old 11-09-2012, 12:59 AM   #3
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by replica9000 View Post
Well it depends what 'Complex command' is. Is 'file2' a result of processing 'file1'?

Maybe something like this might be what you want?
cat 'file1' | awk 'Complex command' | awk ' Different complex command' > 'file2'
Hi ,
Thanks but thats not what i want ,
I m trying to show the output of two entirely independent awk command on the same line
 
Old 11-09-2012, 01:04 AM   #4
pan64
Senior Member
 
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 4,661

Rep: Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253Reputation: 1253
cat file | awk command
is almosst the same as awk command file, but needs more resources.
Probably you can do the following:
awk command1 file1 > result1
awk command2 file2 > result2
paste result1 result2

Last edited by pan64; 11-09-2012 at 01:04 AM. Reason: typo
 
Old 11-09-2012, 02:10 AM   #5
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
I think you want the two commands to run in a group and redirect the output to a file.
Code:
{ awk -f awkscript1 file1; awk -f awkscript2 file2; } >results
You could redirect the output on the first command with > and append on the second command with >>.

Another option is to append to the file from inside your awk scripts.

Last edited by jschiwal; 11-09-2012 at 02:20 AM.
 
Old 11-09-2012, 03:48 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,492

Rep: Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956Reputation: 1956
Or maybe using process substitution:
Code:
paste <(awk 'statements' file1) <(awk 'statements' file2) > result
 
Old 11-09-2012, 09:49 AM   #7
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
cat file | awk command
is almosst the same as awk command file, but needs more resources.
Probably you can do the following:
awk command1 file1 > result1
awk command2 file2 > result2
paste result1 result2
Thanks
Im trying to do it without temporary files inbetween
 
Old 11-09-2012, 09:50 AM   #8
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by colucix View Post
Or maybe using process substitution:
Code:
paste <(awk 'statements' file1) <(awk 'statements' file2) > result
Thanks
When I do this, I get the following error:
Missing name for redirect
 
Old 11-09-2012, 09:52 AM   #9
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by jschiwal View Post
I think you want the two commands to run in a group and redirect the output to a file.
Code:
{ awk -f awkscript1 file1; awk -f awkscript2 file2; } >results
You could redirect the output on the first command with > and append on the second command with >>.

Another option is to append to the file from inside your awk scripts.
Thanks

When I do this it gives me the following error:

{: Command not found.
 
Old 11-09-2012, 10:08 AM   #10
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
may be this would help, my actual command is something like this

1st command : awk '{ print $1, $2 }' file1 | program3

2nd command : awk '( print $2, $3 }' file2 | program3

program 3 is a script that takes input and performs certain calculations and produces output
 
Old 11-09-2012, 12:14 PM   #11
replica9000
Member
 
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', FreeBSD, Android
Posts: 642
Blog Entries: 2

Rep: Reputation: 112Reputation: 112
How about:

awk '{ printf $1, $2 }' file1 | program3 && awk '( print $2, $3 }' file2 | program3
 
Old 11-09-2012, 12:33 PM   #12
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by replica9000 View Post
How about:

awk '{ printf $1, $2 }' file1 | program3 && awk '( print $2, $3 }' file2 | program3
Hi ,
This produces the output one after the other:

AA
BB

but I want them side by side :
AA BB
 
Old 11-09-2012, 12:35 PM   #13
replica9000
Member
 
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', FreeBSD, Android
Posts: 642
Blog Entries: 2

Rep: Reputation: 112Reputation: 112
Quote:
Originally Posted by forumbaba View Post
Hi ,
This produces the output one after the other:

AA
BB

but I want them side by side :
AA BB
Did you use printf instead of print in the first awk? If it's still not side by side with that, your program3 might be causing it.
 
Old 11-09-2012, 12:37 PM   #14
forumbaba
LQ Newbie
 
Registered: Aug 2011
Posts: 19

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by replica9000 View Post
Did you use printf instead of print in the first awk? If it's still not side by side with that, your program3 might be causing it.
When I use printf it prints only the output of the second command
 
Old 11-11-2012, 02:06 AM   #15
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
Quote:
Originally Posted by forumbaba View Post
Thanks

When I do this it gives me the following error:

{: Command not found.
Which shell are you using? Also I didn't know you wanted the outputs to be displayed in different columns.
 
  


Reply

Tags
awk, paste, pipe


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
PHP shell_exec() always gives error "Broken pipe" when using pipe burek Linux - Server 1 01-19-2012 06:04 AM
[SOLVED] How to handle a broken pipe exception (SIGPIPE) in FIFO pipe? zyroot998 Programming 5 03-03-2011 08:10 PM


All times are GMT -5. The time now is 02:27 AM.

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