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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
|
11-08-2012, 11:05 PM
|
#1
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Rep: 
|
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
|
|
|
|
11-08-2012, 11:46 PM
|
#2
|
|
Member
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', Android
Posts: 456
Rep:
|
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'
|
|
|
|
11-09-2012, 12:59 AM
|
#3
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by replica9000
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
|
|
|
|
11-09-2012, 01:04 AM
|
#4
|
|
Senior Member
Registered: Mar 2012
Location: Hungary
Distribution: debian i686 (solaris)
Posts: 2,806
|
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
|
|
|
|
11-09-2012, 02:10 AM
|
#5
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
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.
|
|
|
|
11-09-2012, 03:48 AM
|
#6
|
|
Moderator
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.4 OpenSuSE 12.2
Posts: 9,897
|
Or maybe using process substitution:
Code:
paste <(awk 'statements' file1) <(awk 'statements' file2) > result
|
|
|
|
11-09-2012, 09:49 AM
|
#7
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by pan64
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
|
|
|
|
11-09-2012, 09:50 AM
|
#8
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by colucix
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
|
|
|
|
11-09-2012, 09:52 AM
|
#9
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by jschiwal
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.
|
|
|
|
11-09-2012, 10:08 AM
|
#10
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
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
|
|
|
|
11-09-2012, 12:14 PM
|
#11
|
|
Member
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', Android
Posts: 456
Rep:
|
How about:
awk '{ printf $1, $2 }' file1 | program3 && awk '( print $2, $3 }' file2 | program3
|
|
|
|
11-09-2012, 12:33 PM
|
#12
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by replica9000
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
|
|
|
|
11-09-2012, 12:35 PM
|
#13
|
|
Member
Registered: Jul 2006
Location: Quahog, Rhode Island
Distribution: Debian 'Sid', Android
Posts: 456
Rep:
|
Quote:
Originally Posted by forumbaba
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.
|
|
|
|
11-09-2012, 12:37 PM
|
#14
|
|
LQ Newbie
Registered: Aug 2011
Posts: 19
Original Poster
Rep: 
|
Quote:
Originally Posted by replica9000
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
|
|
|
|
11-11-2012, 02:06 AM
|
#15
|
|
Moderator
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733
|
Quote:
Originally Posted by forumbaba
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 02:49 PM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|