how to find how many lines I have in file by sed (need to ignore spaces and empty lines)
for example
if I have file with 139 lines (line can include only one character) then sed should return 139
lidia
Count Number Of Lines Using Sed Command Here, '=' prints the current line number to standard output. So, combining it with the -n option, it counts the total number of lines in a file passed as an argument.
We primarily use the wc (word count) command to count lines, words, bytes, and characters.
'grep -cv -P '\S' filename' will count the total number of blank lines in the file.
wc. The wc command is used to find the number of lines, characters, words, and bytes of a file. To find the number of lines using wc, we add the -l option. This will give us the total number of lines and the name of the file.
This is a job for grep
, not sed
:
<myfile grep -c '[^[:space:]]'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With