如何取得副檔名為 .tsv 的目錄中的記錄數

如何取得副檔名為 .tsv 的目錄中的記錄數

如何取得副檔名為 .tsv 的目錄中的記錄數。有 100 個 .tsv 文件,我想查看每個文件中的文件名和記錄數以輸出到另一個文件中。

abc.tsv 200
pqr.tsv 300

答案1

假設記錄每行一行,您只需要wc

$ wc -l *.tsv
 5 bar.tsv
 5 foo.tsv
10 total

或者,如果您只想要非空白行,grep對於任何字元:

$ grep -c . *.tsv
bar.tsv:4
foo.tsv:4

wc或者,從輸出中刪除“total”行sed並重定向到檔案:

$ wc -l *.tsv | seq '$d' > counts.txt

答案2

以下範例適用於我的資料夾之一中的 .html 檔案:

$ wc -l *.html
   1479 bookmarks.home.html
    908 bookmarks.html
   1459 bookmarks.office.html
   3846 total

只需將 .html 替換為 .tsv

相關內容