简体   繁体   English

如何在Perl脚本中使用系统命令'grep'

[英]how to use system command 'grep' in perl script

I am trying to count the matching character using grep command in Perl script. 我试图在Perl脚本中使用grep命令计算匹配字符。 Below script is counting whole directory, my desired output should contain only the count of input file not the whole directory, some one help me to do so. 下面的脚本在计算整个目录,我想要的输出应该只包含输入文件的计数,而不是整个目录,有人帮我这样做。

#! use/bin/perl

use strict;


print"Enter file name for Unzip\n";
print"File name: ";
chomp(my $Filename=<>);
system("gunzip -r ./$Filename/*\n");
system('grep -c "@SRR" ./$Filename/*');  

This is giving whole directory count. 这给出了整个目录数。

#! use/bin/perl
use strict;
print"Enter file name for Unzip\n";
print"File name: ";
chomp(my $Filename=<>);
system("gunzip -r ./$Filename\*");
system("grep -c '\@SRR' ./$Filename\*");

Please let know if i misunderstood question. 如果我误解了问题,请告知。 But above code gives us number of lines matching @SRR on zipped filename provided. 但是上面的代码为我们提供了与提供的压缩文件名上的@SRR匹配的行数。

Also you don't need to unzip to count you can directly do this 另外,您无需解压缩即可直接执行此操作

system("zgrep -c '\@SRR' $Filename")

instead of 代替

 system("gunzip -r ./$Filename\*");
 system("grep -c '\@SRR' ./$Filename\*");

my $var= cat filename | grep "your word" 我的$ var = cat filename | grep "your word" cat filename | grep "your word" ; cat filename | grep "your word"

Thanks, nilesh. 谢谢,尼罗什。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM