f



pass nth argument to a command from grep

Hi,

how to pass output of a grep command as nth argument to a command.
ex: cat x | grep y | scp <arg-goes-here> <rest-of-the-command>

thanks
0
sinbad
12/12/2016 6:11:19 AM
comp.unix.programmer 10848 articles. 0 followers. kokososo56 (349) is leader. Post Follow

3 Replies
247 Views

Similar Articles

[PageSpeed] 42

On Sun, 11 Dec 2016 22:11:19 -0800 (PST), sinbad
<sinbad.sinbad@gmail.com> wrote:

>Hi,
>
>how to pass output of a grep command as nth argument to a command.
>ex: cat x | grep y | scp <arg-goes-here> <rest-of-the-command>

I wasn't sure exactly what you mean, but the man page for xargs seemed
like a good place to start. I found the -I flag:

$ echo a1 a2 | xargs echo x1 x2 x3
x1 x2 x3 a1 a2
$ echo a1 a2 | xargs -I{} echo {} x1 x2 x3
a1 a2 x1 x2 x3

I hope this helps. If it doesn't, can you give an example of what
you're trying to do?

Louis
0
Louis
12/12/2016 10:41:31 AM
On Monday, 12 December 2016 06:11:24 UTC, sinbad  wrote:
> Hi,
> 
> how to pass output of a grep command as nth argument to a command.
> ex: cat x | grep y | scp <arg-goes-here> <rest-of-the-command>
> 
> thanks

Look up Command Substitution in your shell documentation.

scp "$(cat x | grep y)" <rest-of-the-command>
0
guinness
12/12/2016 12:03:51 PM
On 2016-12-11 22:11, sinbad wrote:

> how to pass output of a grep command as nth argument to a command.
> ex: cat x | grep y | scp <arg-goes-here> <rest-of-the-command>

Note: this really belongs in comp.unix.shell.

And indeed, the most general answer is, transform the output with awk or
sed into a shell command and run a shell as the last part of the
pipeline.  You can eliminate the grep too because the awk or sed can do
the job.

You can eliminate the useless kitty in the front as well, but that is
really veering into pet topics.

-- 
Please *no* private Cc: on mailing lists and newsgroups
Personal signed mail: please _encrypt_ and sign
Don't clear-text sign: http://cr.yp.to/smtp/8bitmime.html

0
Ian
12/12/2016 5:28:33 PM
Reply: