[英]Percentage or number of files processed by grep command
If I am searching/checking for an KeyWord/String using GREP command from 1000 files for example; 例如,如果我正在使用GREP命令从1000个文件中搜索/检查关键字/字符串; then is there any option/way to see/display the percentage or number of files processed by the GREP command...?.
那么是否有任何选项/方式可以查看/显示GREP命令处理的文件的百分比或数量...?
Just I would like to know how long further it will take to complete the search process. 我想知道完成搜索过程需要多长时间。
Please help 请帮忙
try awk
. 尝试
awk
。 This will print a messages suggesting the file number being processed, followed by the line matching the pattern. 这将打印一条消息,提示正在处理的文件号,然后显示与模式匹配的行。 I have chosen the pattern here to be character p as that was easy for my testing.
我在这里选择的模式是字符p,因为这对我的测试很容易。 You can replace with any valid regex for your purpose.
您可以根据需要使用任何有效的正则表达式替换。
awk -v PAT="p" 'FNR == 1 { n++; printf "Processing %d of %d files\n", n, ARGC - 1 >> "/dev/stderr"} FILENAME ~ /.gz$/ {print "Skipping gz file: ", FILENAME; nextfile} /PAT/'
Explanation 说明
awk -v PAT="p" '
FNR == 1 { # Every first line of the file
n++; # Counter for file being processed
printf "Processing %d of %d files\n", # Print message
n, # file number
ARGC - 1 # Number of files on CLI
>> "/dev/stderr" # Redirect to stderr
}
FILENAME ~ /.gz$/ { # Skip gunzip files
print "Skipping gz file: ", FILENAME;
nextfile # move to next file
}
/PAT/ # Pattern to print
'
UPDATE 更新
Updated the code to skip the gunzip (.gz) files when processing. 更新了代码以在处理时跳过gunzip(.gz)文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.