cod*_*lic 14
如果没有答案对你有好处,我会尽力获得赏金;-)
#!/usr/bin/perl
# Lines beginning with a hash (#) denote optional comments,
# except the first line, which is required,
# see http://en.wikipedia.org/wiki/Shebang_(Unix)
use strict; # http://perldoc.perl.org/strict.html
use warnings; # http://perldoc.perl.org/warnings.html
# http://perldoc.perl.org/perlsyn.html#Compound-Statements
# http://perldoc.perl.org/functions/defined.html
# http://perldoc.perl.org/functions/my.html
# http://perldoc.perl.org/perldata.html
# http://perldoc.perl.org/perlop.html#I%2fO-Operators
while (defined(my $line = <>)) {
# http://perldoc.perl.org/functions/split.html
my @chunks = split ' ', $line;
# http://perldoc.perl.org/functions/print.html
# http://perldoc.perl.org/perlop.html#Quote-Like-Operators
print "$chunks[0] $chunks[2]\n";
}
Run Code Online (Sandbox Code Playgroud)
要运行此脚本,script.pl请将其命名为
perl script.pl FILE
Run Code Online (Sandbox Code Playgroud)
FILE您要解析的文件在哪里.另见http://perldoc.perl.org/perlrun.html.祝好运!;-)
mob*_*mob 13
perl -lane 'print "@F[0,2]"' file
Run Code Online (Sandbox Code Playgroud)
T.E*_*.D. 13
对于像perl这样强大的东西来说,这真的是一种浪费,因为你可以在一个简单的awk行中做同样的事情.
awk '{ print $1 $3 }'
while ( <> ) {
my @fields = split;
print "@fields[0,2]\n";
}
Run Code Online (Sandbox Code Playgroud)
而且只是为了变化,在Windows上:
C:\Temp> perl -pale "$_=qq{@F[0,2]}"
Run Code Online (Sandbox Code Playgroud)
在Unix上
$ perl -pale '$_="@F[0,2]"'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
26325 次 |
| 最近记录: |