Count source code Lines shell script [00 original]

Source: Internet
Author: User
Today I wrote a shell script that counts the number of source lines in a directory, as follows:
#!/bin/bash
Find. -Name *. Java > Srcfilespathname
Count = $ (wc-l srcfilespathname) # Record the number of source files
echo "Number of source generation files = $count"

While Read PathName
Todo
Countandpath = $ (wc-l $pathName)
echo $countAndPath >> T1
Done < Srcfilespathname

linesum = 0 # Total Row count

While Read Countandpath
Todo
LineCount = ' echo ' $countAndPath | Awk-f ' ' {print '} ' # take the first field, which is the number of rows
Linesum = ' expr $lineCount + $lineSum '
Done < T1

echo "Total number of source lines = $lineSum"
RM Srcfilespathname
RM T1

Exit 0
Later, the master gave a simpler answer, a line of command is enough:-)

Find-name ' *.java '-type f-exec cat {};  | Wc-l
Oh, shell script is really profound ah.
:-)
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.