Re: passing arguments within pipes



Seb wrote:
Hi,

How should a 2nd and 3rd argument be passed to a function taking 3
arguments in a pipe? For example:


ls | gawk 'FNR == 3' | fun


Here fun takes 3 arguments and of course I would like its 1st one to be
what's passed from gawk. I'm obviously missing something in the docs
about how to do this. Thanks in advance for any suggestions.

Wait, wait - what are you trying to do here?

If fun takes _arguments_ you should not pipe in data (which are read by
fun through stdin and not through the argv list).

And you just read the third line (FNR==3) of the input stream (from ls),
is that intentional? Or do you rather want to select lines with 3 fields
(NF==3) to be passed to fun?

Shall fun read and process many "lines" of three argument data?

Some possibilities, depending on what you really want to do...

fun $( ls | gawk 'FNR == 3' ) ## BTW, equivalent to NR==3
fun $( ls | gawk 'NF == 3' )

ls | gawk 'NF == 3' | xargs -n2 fun

ls | gawk 'NF == 3' | while read -r a1 a2 a3; do fun $a1 $a2 $a3; done

Or let us know what you need.

Janis



Cheers,

.



Relevant Pages

  • Re: Chicago Show Doesnt Seem To Be Much Fun
    ... there was more fun at this show than any other Chicago show ... I have been an attendee of the Chicago pipe show for more years than I can ... and the hotel staff has informed me that they are drilling a brand new ... water well and ...
    (alt.smokers.pipes)
  • Re: passing arguments within pipes
    ... On 2007-04-09, Seb wrote: ... arguments in a pipe? ... Here fun takes 3 arguments and of course I would like its 1st one to be ... A Problem-Solution Approach (2005, Apress) ...
    (comp.unix.shell)
  • Re: Chicago Show Doesnt Seem To Be Much Fun
    ... there was more fun at this show than any other Chicago show ... I have been an attendee of the Chicago pipe show for more years than I can count. ... and the hotel staff has informed me that they are drilling a brand new water well and replacing a bunch of the old mains. ...
    (alt.smokers.pipes)
  • Re: Whatre you reading?
    ... What a fun read... ... Smoked a VSG while pushing through a large portion of The Color of Magic. ... "My advice is to treat your pipe like your pecker. ...
    (alt.smokers.cigars)
  • Re: Pipe Trip Ideas Wanted
    ... Knoxville Cigar - both stores. ... It would be fun to plot out such a wandering and eventually just do it. ... they should cater primarily to pipe smokers ...
    (alt.smokers.pipes)