![](/img/trans.png)
[英]Count the number of lines in a text file that contain a specific character (Linux)?
[英]Count number of rows in a text file using linux
我想知道如何使用Linux獲取文本文件中的行數。 我已經嘗試過“ wc”和“ wc -l”,但是都只顯示行數(列)而不顯示行數。 任何想法?
wc -l < <filename>
為我顯示行
示例文件編號為1-7
輸出:
scottsmudger@ns207588:~ $wc -l < test
7
從手冊頁:
-l, --lines
print the newline counts
如果要獲取每行中的字段數,可以使用awk:
在這種情況下,我們可以使用一個稱為NF的內部內置變量,該變量將跟蹤字段編號。 通常,最大字段數為100。
awk '{ print NF }' file_name
該命令將打印每行中的列數
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.