General description:
I had a couple of times the same issue, that I solved by doing an step by step script. But I know that with pipe, one-liners would make my life way easier.
Simply:
command1 -flag target.file | command2 -flag
As far as I understand, the command2
is applied over the output of command1 -flag target.file
. However, command2
has an extra argument that has to be added at the end. So, it would be read as:
command2 -flag OUTPUTOFCOMMAND1 argument2
When I try to pipe directly with |
, of course I don't get the desired command, as it passes the output to the end of the second instruction. I'd like to redirect the piped output to an specific part of the second instruction. Something like this:
command1 -flag target.file | command2 -flag PIPEOUTPUT1HERE argument2
I've found a similar question in here: Pass the output of previous command to next as an argument, but i would like a more general, and simple approach. As I have used, without sucess:
command1 | xargs -I{} command2 {}
Which is basically doing command2 $(command1)
, but I would like to pipe the entire output of it. Like a simple ls | grep "something"
My specific case:
I want to take out the first line of a dat file, and split it every 11 lines:
$ tail -n +2 ac_sweep_m+_-30.00mT.rx | xargs -I{} split -l 2 {}
But passes every line of the previous output at theend of the second instruction:
"ac_sweep_m+_-30.00mT_"
split: cannot open '0.000000e+00 0.000363094 -0.000518363 -0.000389763 0 ' for reading: No such file or directory
split: cannot open '2.800000e-11 -0.0853443 -0.00230621 -0.000370474 0 ' for reading: No such file or directory
split: cannot open '6.700000e-11 -0.205325 -0.00375738 0.000241809 0 ' for reading: No such file or directory
How can I direct the pipe exactly into an specific position?