grep -ia '^Windows Installer' Galant01.txt Galant02.txt | awk -F '\t' '{print substr($1,1,index($1,":")) $4 "<br>"}' ;
输出产生:
Galant01.txt:Manual<br>
Galant02.txt:Manual<br>
最好显示:
Galant01.txt,Galant02.txt:Manual
我们的想法是将类似的输入组合在一起并保持下面的完整:
Galant01.txt:Automatic
Galant02.txt:Manual
答案 0 :(得分:-1)
您可以通过以下方式输出输出:
perl -e '@l=<>; chomp @l; map { /(.*?):(.*?)<br>/ and push @{$h{$2}}, $1; } @l; map { print join(",", @{$h{$_}}), ":$_\n"} keys %h'
将awk
部分合并到此处,这是完整的命令行:
grep -ia '^Windows Installer' Galant01.txt Galant02.txt | perl -e '@l=<>; chomp @l; map { /(.*?):(.*?)\t(.*?)\t(.*?)\t(.*)/; push @{$h{$5}}, $1; } @l; map { print join(",", @{$h{$_}}), ":$_<br>\n"} keys %h'
不幸的是它不短,所以你可以将它放在filter.pl
文件中:
#!/usr/bin/perl
@l=<>; # read all input lines
chomp @l; # safely remove EOL
map { # process input lines
/(.*?):(.*?)\t(.*?)\t(.*?)\t(.*)/; # match grep output
push @{$h{$5}}, $1; # add filename to hash
} @l;
map { # process hash
print join(",", @{$h{$_}}), ":$_<br>\n" # print filenames and key
} keys %h
并使用grep -ia ..... | filter.pl