我有一組具有類似命名模式的檔案。我正在嘗試一次性獲取所有檔案的總行數(沒有標題)。但是我在使用命令時遇到了問題。
我努力了:
sed '1d' IN-Pass-30* | wc -l
和
awk 'END {print NR-1}' IN-Pass-30*
但是每次它只從一個檔案中減去標題計數。我在這里做錯了什么?
uj5u.com熱心網友回復:
你很接近。將 sed 命令包裝在 bash glob 回圈中:
for f in IN-Pass-30*; do sed '1d' "$f"; done | wc -l
uj5u.com熱心網友回復:
我建議以下“簡單”解決方案:
Prompt> find ./ -maxdepth 1 -name "IN-Pass-30*" | wc -l
53
Prompt> cat IN-Pass-30* | wc -l
1418549
Prompt> echo $(($(cat IN-Pass-30* | wc -l) - $(find ./ -maxdepth 1 -name "IN-Pass-30*" | wc -l)))
1418496
這是什么意思?
Prompt> find ./ -maxdepth 1 -name "IN-Pass-30*" | wc -l
// find all files inside that directory without checking subdirectories.
// once they are found, count them.
Prompt> cat IN-Pass-30* | wc -l
// use `cat` to concatenate all files' content.
// at the end, count the amount of lines.
Prompt> echo $$(a - b))
// calculate the difference between a and b.
Prompt> echo $(command)
// show (or do whatever with it) the result of a command
哦,整個想法是每個檔案的標題占 1 行,所以通過計算所有檔案中的行數,減去檔案的數量(與標題行的數量相同),你應該得到期望的結果。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/537364.html
標籤:unix
上一篇:Unix以編程方式重定向命令
