【发布时间】:2017-02-01 06:50:35
【问题描述】:
例如,我有一个文件test.json,其中包含一系列包含以下内容的行:
header{...}body{...}- 其他文字(与其他文字一样)
- 空行
我想运行一个返回以下内容的脚本
Counted started on : test.json
- headers : 4
- body : 5
- <others>
Counted finished : <time elapsed>
到目前为止,我得到的是这个。
count_file() {
echo "Counted started on : $1"
#TODO loop
cat $1 | grep header | wc -l
cat $1 | grep body | wc -l
#others
echo "Counted finished : " #TODO timeElapsed
}
编辑:
编辑问题并添加代码sn-p
【问题讨论】:
-
显示实际文件的一些片段
-
“预期结果”不应该是您对回答您问题的人的期望(这表明您目前没有付出任何努力)。它应该是您期望的输出。
-
你可以简单地使用
cat $1 |grep header |...而不是grep header $1 |...