【发布时间】:2021-03-18 16:19:39
【问题描述】:
在执行我的脚本时,我使用了 2 个输入参数,一个用于文件夹,另一个用于字符串匹配。这是我的代码。
使用两个参数调用文件 // 确保这一点
if [ $# -ne 2 ]
then
echo "Incorrect use. Try: Sudo $0 FILE PATTERN"
exit 2
fi
查找匹配的位置以及匹配发生的次数。
echo ""
echo "Your pattern ${2} occurs in the following files:"
grep -r -i -l -c $2 $1
echo ""
echo "Pattern match ${2} found this many times:"
grep -r -o -i $2 $1 | wc -l
用名称和大小(字节)打印目录中的文件
echo ""
echo "Here are the files from the specified parameter search:"
ls -l | awk '{print $9 "\t" $5}'
创建一个数组并存储在模式匹配中至少出现两次的文件名。
grep $2 $1 -r -c | cut -d: -f1 | uniq -d
我似乎无法找到仅出现 2 次的文件存储在数组中,感谢所有帮助!!
【问题讨论】:
-
请修正您问题的格式。
-
你真的需要使用
sudo吗?