"paste" and "xargs"?
am 28.09.2007 19:53:21 von spluque
Hi,
I have a hard time understanding how 'xargs' works, but it seems to be the
tool necessary for having 'paste' take two args from stdin. The idea is
as:
echo -e "1 2\n3 4\n5 6" > paste_try
paste $(head -n 1 paste_try) $(tail -n 1 paste_try)
which of course fails, but hope you can see what I mean. Would 'xargs'
work here? I'd appreciate any pointers. Thanks.
--
Seb
Re: "paste" and "xargs"?
am 28.09.2007 20:20:27 von Cyrus Kriticos
Seb wrote:
>
> I have a hard time understanding how 'xargs' works, but it seems to be the
> tool necessary for having 'paste' take two args from stdin. The idea is
> as:
>
> echo -e "1 2\n3 4\n5 6" > paste_try
> paste $(head -n 1 paste_try) $(tail -n 1 paste_try)
>
> which of course fails, but hope you can see what I mean. Would 'xargs'
> work here? I'd appreciate any pointers. Thanks.
[bash]
$ paste <(head -n 1 paste_try) <(tail -n 1 paste_try)
1 2 5 6
--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Re: "paste" and "xargs"?
am 28.09.2007 20:22:19 von Bill Marcum
On 2007-09-28, Seb wrote:
> Hi,
>
> I have a hard time understanding how 'xargs' works, but it seems to be the
> tool necessary for having 'paste' take two args from stdin. The idea is
> as:
>
>
> echo -e "1 2\n3 4\n5 6" > paste_try
> paste $(head -n 1 paste_try) $(tail -n 1 paste_try)
>
>
> which of course fails, but hope you can see what I mean. Would 'xargs'
> work here? I'd appreciate any pointers. Thanks.
>
>
That fails because the results of "head -n 1 paste_try" and
"tail -n 1 paste_try" aren't filenames. Well, they could be, but I don't
think that's what you want.
What might work is
awk 'NR==1{x=$0} END{print x,$0}'
Re: "paste" and "xargs"?
am 28.09.2007 20:28:41 von Cyrus Kriticos
Cyrus Kriticos wrote:
> [bash]
>
> $ paste <(head -n 1 paste_try) <(tail -n 1 paste_try)
> 1 2 5 6
or perhaps something like this:
$ tac paste_try | paste paste_try -
1 2 5 6
3 4 3 4
5 6 1 2
--
Best regards | "The only way to really learn scripting is to write
Cyrus | scripts." -- Advanced Bash-Scripting Guide
Re: "paste" and "xargs"?
am 28.09.2007 21:57:20 von spluque
On Fri, 28 Sep 2007 14:22:19 -0400,
Bill Marcum wrote:
[...]
> That fails because the results of "head -n 1 paste_try" and "tail -n 1
> paste_try" aren't filenames. Well, they could be, but I don't think
> that's what you want. What might work is
> awk 'NR==1{x=$0} END{print x,$0}'
Nice, I should have thought of awk for this!
Thank you both (I didn't know about <( in bash either)!
--
Seb