> Now, does anyone have a simpler way than using the ".map" above?
There were a few in the thread! Here's my golfing, unlike the others, this preserves the order of the lines (which may or may not be desired) raku -ne '.say if $++ == any 6,3,1' line0-10.txt -y On Tue, Aug 25, 2020 at 12:03 PM William Michels via perl6-users < perl6-us...@perl.org> wrote: > If Todd wants to print lines containing "Line 1", "Line 3", and "Line 7", > he's going to have to correct for zero-indexing: > > user@book:~$ raku -e '$*IN.lines[ 1,3,7 ].join("\n").put;' < Lines.txt > Line 2 > Line 4 > Line 8 > > #Below: subtracting one from (1,3,7) gives the return he wants: > > user@book:~$ raku -e '$*IN.lines[ (1,3,7).map: { $_ - 1 } > ].join("\n").put;' < Lines.txt > Line 1 > Line 3 > Line 7 > > Now, does anyone have a simpler way than using the ".map" above? > > HTH, Bill. > > > > On Tue, Aug 25, 2020 at 10:46 AM Andy Bach <andy_b...@wiwb.uscourts.gov> > wrote: > >> Ah, I see, the -n reads a line and then my lines on $*IN starts with the >> next one >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my >> @x = $*IN.lines(); say @x[0,1,7,3]; " >> (Line 0 Line 1 Line 7 Line 3) >> >> and so $*IN is the default for lines() >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -e "my >> @x = lines(); say @x[0,1,7,3]; " >> (Line 0 Line 1 Line 7 Line 3) >> >> This hangs, with and without the -n >> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = >> $*IN.lines(); say @x[0,1,7,3]; " lines.txt >> >> Though: >> C:\> "\Program Files (x86)\rakudo\bin\raku.exe" -ne "my @x = lines(); >> say @x[0,1,7,3]; " lines.txt >> (Line 1 Line 2 Line 8 Line 4) >> Cannot do 'get' on a handle in binary mode >> in block <unit> at -e line 1 >> >> a >> >> Andy Bach, BS, MSCMECFA >> Systems Mangler >> Internet: andy_b...@wiwb.uscourts.gov >> Voice: (608) 261-5738, Cell: (608) 658-1890 >> >> "The three great problems of computer science: >> compiler complexity and 'off-by-one' errors". >> https://martinfowler.com/bliki/TwoHardThings.html >> >> ------------------------------ >> *From:* Andy Bach <andy_b...@wiwb.uscourts.gov> >> *Sent:* Tuesday, August 25, 2020 12:18 PM >> *To:* Parrot Raiser <1parr...@gmail.com> >> *Cc:* perl6-users <perl6-us...@perl.org>; ToddAndMargo < >> toddandma...@zoho.com> >> *Subject:* Re: print particular lines question >> >> On Win10 >> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "say lines()[1,7,3]; " >> (Line 2 Line 8 Line 4) >> (Line 11 Nil Nil) >> >> C:\>type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "say lines()[1,7,3].join(qq~\n~); " >> Line 2 >> Line 8 >> Line 4 >> Use of Nil in string context >> in block at -e line 1 >> Use of Nil in string context >> in block at -e line 1 >> Line 11 >> >> and, speaking of that off by one problem ... lines.txt does start with >> "line 0" >> C:\> type lines.txt | "\Program Files (x86)\rakudo\bin\raku.exe" -ne >> "my @x = $*IN.lines(); say @x[0,1,7,3]; " >> (Line 1 Line 2 Line 8 Line 4) >> >> a >> >> Andy Bach, BS, MSCMECFA >> Systems Mangler >> Internet: andy_b...@wiwb.uscourts.gov >> Voice: (608) 261-5738, Cell: (608) 658-1890 >> >> "The three great problems of computer science: >> compiler complexity and 'off-by-one' errors". >> https://martinfowler.com/bliki/TwoHardThings.html >> >> ------------------------------ >> *From:* Parrot Raiser <1parr...@gmail.com> >> *Sent:* Tuesday, August 25, 2020 11:22 AM >> *To:* Andy Bach <andy_b...@wiwb.uscourts.gov> >> *Cc:* perl6-users <perl6-us...@perl.org>; ToddAndMargo < >> toddandma...@zoho.com> >> *Subject:* Re: print particular lines question >> >> That will golf a little (and improve it) to: >> >> $ raku -e '.say for lines()[3,2,5]' lines.txt >> >> but you have to remember that it's zero-based. I used the first sample >> file and got >> Line 4 >> Line 3 >> Line 6 >> >> "The three great problems of computer science: compiler complexity and >> 'off-by-one' errors". >> >> >> On 8/25/20, Andy Bach <andy_b...@wiwb.uscourts.gov> wrote: >> >> Assigning `my @x=$_.lines` puts everything into $x[0] >> > >> > Trying this on windows >> > >> > C:\> raku.exe -e "my @x = 'lines.txt'.IO.lines; say >> > @x[1,7,3].join(qq~\n~); " >> > Line 1 >> > Line 7 >> > Line 3 >> > >> > or >> > C:\> raku.exe -e " say 'lines.txt'.IO.lines[1,7,3].join(qq~\n~); " >> > Line 1 >> > Line 7 >> > Line 3 >> > >> > a >> > >> > Andy Bach, BS, MSCMECFA >> > Systems Mangler >> > Internet: andy_b...@wiwb.uscourts.gov<mailto: >> andy_b...@wiwb.uscourts.gov> >> > Voice: (608) 261-5738, Cell: (608) 658-1890 >> > >> > Every man has the right to an opinion but no man >> > has a right to be wrong in his facts. Nor, above all, >> > to persist in errors as to facts. Bernard Baruch >> > >> > ________________________________ >> > From: ToddAndMargo via perl6-users <perl6-us...@perl.org> >> > Sent: Monday, August 24, 2020 9:35 PM >> > To: perl6-users <perl6-us...@perl.org> >> > Subject: print particular lines question >> > >> > Hi All, >> > >> > I seems I should know how to do this, but >> > I am drawing a blank. >> > >> > $ cat Lines.txt | raku -ne 'say $_;' >> > Line 1 >> > Line 2 >> > Line 3 >> > Line 4 >> > Line 5 >> > Line 6 >> > Line 7 >> > Line 8 >> > Line 9 >> > Line 10 >> > Line 11 >> > >> > >> > I want to print liens 1, 3, and 7. >> > >> > Assigning `my @x=$_.lines` puts everything into $x[0] >> > >> > >> > Many thanks, >> > -T >> > >> >