LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   pipe and paste (http://www.linuxquestions.org/questions/linux-newbie-8/pipe-and-paste-4175436346/)

forumbaba 11-09-2012 12:05 AM

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

replica9000 11-09-2012 12:46 AM

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'

forumbaba 11-09-2012 01:59 AM

Quote:

Originally Posted by replica9000 (Post 4825503)
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

pan64 11-09-2012 02:04 AM

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

jschiwal 11-09-2012 03:10 AM

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.

colucix 11-09-2012 04:48 AM

Or maybe using process substitution:
Code:

paste <(awk 'statements' file1) <(awk 'statements' file2) > result

forumbaba 11-09-2012 10:49 AM

Quote:

Originally Posted by pan64 (Post 4825526)
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

forumbaba 11-09-2012 10:50 AM

Quote:

Originally Posted by colucix (Post 4825619)
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

forumbaba 11-09-2012 10:52 AM

Quote:

Originally Posted by jschiwal (Post 4825559)
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.

forumbaba 11-09-2012 11:08 AM

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

replica9000 11-09-2012 01:14 PM

How about:

awk '{ printf $1, $2 }' file1 | program3 && awk '( print $2, $3 }' file2 | program3

forumbaba 11-09-2012 01:33 PM

Quote:

Originally Posted by replica9000 (Post 4825953)
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

replica9000 11-09-2012 01:35 PM

Quote:

Originally Posted by forumbaba (Post 4825966)
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.

forumbaba 11-09-2012 01:37 PM

Quote:

Originally Posted by replica9000 (Post 4825969)
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

jschiwal 11-11-2012 03:06 AM

Quote:

Originally Posted by forumbaba (Post 4825859)
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.


All times are GMT -5. The time now is 05:11 AM.