Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use find, wc, and sed to count lines

Tags:

find

bash

sed

wc

I was trying to use sed to count all the lines based on a particular extension.

find -name '*.m' -exec wc -l {} \; | sed ... 

I was trying to do the following, how would I include sed in this particular line to get the totals.

like image 422
Berlin Brown Avatar asked Sep 11 '09 17:09

Berlin Brown


People also ask

How do I count the number of lines in Linux?

Wc Command in Linux (Count Number of Lines, Words, and Characters) On Linux and Unix-like operating systems, the wc command allows you to count the number of lines, words, characters, and bytes of each given file or standard input and print the result.

How do I count the number of lines in a text file in Linux?

Using “wc -l” But one of the easiest and widely used way is to use “wc -l”. The wc utility displays the number of lines, words, and bytes contained in each input file, or standard input (if no file is specified) to the standard output.

How do I count the number of lines in a file Unix?

The tool wc is the "word counter" in UNIX and UNIX-like operating systems, but you can also use it to count lines in a file by adding the -l option. wc -l foo will count the number of lines in foo .


1 Answers

You may also get the nice formatting from wc with :

wc `find -name '*.m'` 
like image 194
Emmanuel BERNAT Avatar answered Sep 23 '22 21:09

Emmanuel BERNAT