wc -l <file>
will print out the number of lines in <file>.If you have a collection of files (.csv in the example below), and want to know how many rows are in each file, the command:
for f in *.csv; do wc -l $f; done
will print out a list of all the files ending in .csv, along with the number of lines in them.To print the number of lines, without the filename, the cut command can be used, with the following parameters:
cut -d' ' -f1
Combining them, we can use:
for f in *.csv; do wc -l $f |cut -d' ' -f1; done
to print out just the number of lines in each file ending in .csv in the directory.
Hi,
ReplyDeletenice solution, I figured it might be easier using wc -l *.csv, but you're right.
But I found another solution:
wc -l *.cfg|sed -e 's/^[ ]*//'|cut -d" " -f1
;)
cheers
Nice solution, I never really think of using sed for this kind of stuff, but it works well!
Delete