I want to know how to get the number of rows in a text file using Linux. I have tried "wc " and "wc -l ", but both display only the number of lines (columns) not the rows. Any idea?
wc -l < <filename>
displays lines for me
example file with numbers 1 - 7
outputs:
scottsmudger@ns207588:~ $wc -l < test
7
From the man page:
-l, --lines
print the newline counts
if you want to get the number of fields in each line you can use awk :
In this case we can use an internal built-in variable called NF, which will keep track of field numbers. Typically, the maximum field number will be 100.
awk '{ print NF }' file_name
this command will print the number of columns in each line
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.