我有一堆日志文件.我需要找出所有文件中出现字符串的次数.
grep -c string *
Run Code Online (Sandbox Code Playgroud)
回报
...
file1:1
file2:0
file3:0
...
Run Code Online (Sandbox Code Playgroud)
使用管道我只能获得具有一个或多个出现次数的文件:
grep -c string * | grep -v :0
...
file4:5
file5:1
file6:2
...
Run Code Online (Sandbox Code Playgroud)
我怎样才能得到合并计数?(如果它返回file4:5, file5:1, file6:2,我想回来8.)
以此代码为例.假装它是一个HTML /文本文件,如果我想知道出现的总次数,echo我怎么能用bash做呢?
new_user()
{
echo "Preparing to add a new user..."
sleep 2
adduser # run the adduser program
}
echo "1. Add user"
echo "2. Exit"
echo "Enter your choice: "
read choice
case $choice in
1) new_user # call the new_user() function
;;
*) exit
;;
esac
Run Code Online (Sandbox Code Playgroud)