(back on the desktop for the moment...) On Fri, Aug 4, 2017 at 5:04 PM, ToddAndMargo <toddandma...@zoho.com> wrote:
> On 08/04/2017 01:00 PM, ToddAndMargo wrote: > >> How do I do this with a perl one liner? >> >> $ echo "a b c d" | awk '{print $2}' >> b >> > > $ echo "a b c d" | perl6 -n -e 'say lines ~ "\n" ~ .words[2];' > ( c) > > without "-n" ".words" doesn't work. > > With "-n" "lines" doesn't work Yes, you've been given a number of things at cross purposes with each other. So: if you use -n or -p then your expression (via -e) will be run as if it were wrapped in for $*IN.lines { < your -e here > $_.print; # only if you used -p } That is, if you use -n, you do not want to use lines; your code already runs on each line. If this is not what you want then you don't want -n or -p. And if you want to use words in that case, you need to invoke it on whatever string you are trying to split into words (the default is $_, which will be the current line of input with -n or -p). This leaves me confused as to what `lines ~ "\n" ~ .words[2]` would be doing, though. Read all the input into lines, concatenate them all, append a newline, then try to read *more* input and split to words? Because that's what you wrote (or would have written without -n; with -n, you have read the first line into $_, where words will find it, and lines will eat the remaining lines of input). What exactly are you trying to do here? -- brandon s allbery kf8nh sine nomine associates allber...@gmail.com ballb...@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net