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 |
![]() |
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 |
![]() |
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 |
![]() |
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 |
![]() |