windows - Perl oneliner: print first lines into file -
i want print first 10 lines of huge file new file. oneliner can print lines on monitor:
> perl -ne "print if $. < 10" in.csv
i tried this:
> perl -ne "print if $. < 10" in.csv >out.txt
but create file out.txt without writing first lines it. wrong code?
help
windows 7 / strawberry perl
update1:
if send print result on monitor using:
> perl -ne "print if $. <= 10" in.csv
the program not stop, is, first ten lines output on monitor not end with:
>
i have stop program using ctrl+c.
using simple csv-file ikegami (just rows) onliner works. assume there within csv-file.
update 2:
original onliner:
> perl -ne "print if $. <= 10" in.csv >out.txt
works. have wait seconds. csv-file 2 gb large. onliner:
> perl -pe "exit if $. > 10" in.csv >out.txt
gives result immediately. conclusion: first onliner goes through rows, second exit after 10 rows.
sorry bother problem. learnt lesson: use appropriate onliner or wait more seconds.
hum? that's correct (except < 10
should <= 10
):
>type in.csv b c d e f g h j k l m n ... z >perl -ne "print if $. <= 10" in.csv >out.txt >type out.txt b c d e f g h j >
a faster solution exit when has no more print rather printing entire file.
perl -pe"last if $. > 10" in.csv >out.txt
Comments
Post a Comment