繁体   English   中英

Bash脚本:跳过文件和grep

[英]Bash scripting: Skipping files and grep

Bash脚本并不是我的强项。 我有一个文件结构为

% comment
filename1 pattern-to-search1
filename1 pattern-to-search2
...

我想为filename中的每一行编写一个脚本,用于grep filename以实现从pattern-to-mat

到目前为止,我有

while read file p
do
    if [ "${file:0:1}" != "%" ]
    then
    grep -o "$p" $file | wc -l
    fi
done
echo -e "\nDone."

但是它不会跳过以%开头的文件。 有任何想法吗?

我只是做

grep -v '^%' | while read file p
do
    grep -c "$p" -- "$file"
done

这样,注释行甚至不会到达 read循环

暂无
暂无

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

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