1 perl
I have a source text in a file and looking for a code that would take the second (or n-th - in general) row from this file and print to a seperate file.
Any idea how to do this?
You can do this natively in Perl with the flip-flop operator and the special variable $. (used internally by ..), which contains the current line number:
# prints lines 3 to 8 inclusive from stdin:
while (<>)
{
print if 3 .. 8;
}
Run Code Online (Sandbox Code Playgroud)
Or from the command line:
perl -wne'print if 3 .. 8' < filename.txt >> output.txt
Run Code Online (Sandbox Code Playgroud)
You can also do this without Perl with: head -n3 filename.txt | tail -n1 >> output.txt
| 归档时间: |
|
| 查看次数: |
1079 次 |
| 最近记录: |