假设我想收集一些关于 .txt 文件的统计信息,如下所示:
misses 15
hit 18
misses 20
hit 31
我写了一个 bash 脚本,它只打印每一行:
#!/bin/bash
while read line
do
echo $line
done <t.txt
我现在想要的是:这个例子是伪代码:
read every line
if first column is miss add the number to total misses
if hits add the number to total hits
print total hits, and total misses in a file
我已经搜索过了,这可以用 awk 完成。你能用 awk 帮忙吗?