hi all
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
hi all
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
You can try:
sed -n '/[^[:space:]]/p' filename | wc -l
Here sed
prints only those line that have at least one non-space char and wc
counts those lines.
Use nawk instead of sed.
nawk 'NF{c++}END{print "total: "c}' file
sed '/^ *$/ d' filename | wc -l
Here, sed
prints the lines after deleting all the lines with 0 or more spaces from beginning to the end. wc -l
is to count the number of these lines.