Shell script implements C-language code line statistics _linux Shell

Source: Internet
Author: User
Tags comments

The

Writes a rough C-language code line statistic script, and there are still some bugs, and the efficiency is not high. The script is mainly to remove most of the annotation after the number of lines, equivalent to doing a part of preprocessing work. Here's the code:

#!/bin/bash filename=$1 echo "' WhoAmI '" if [$#-lt 1];then echo "usage:./scripts filename" exit-1 fi if [!-F
$filename];then echo "$filename is not a file" exit 0;
Fi user= "' WhoAmI '" If ["$user"!= "root"];then echo "Use scripts with Root" exit 0; Fi #删除空行, empty rows include: Tables + space sed '/^[[:blank:]]*$/d ' $filename > "${filename}_backup" #删除//The line Sed-i '/^[[:blank: ]]*\/\//d ' "${filename}_backup" #/*xxxxx*/#打印/* All start lines grep-n ' [[: blank:]]*/[*] ' "${filename}_backup" | awk ' begin{fs= ': "}{print" > "Start.txt" #打印 * * all end lines grep-n ' [*]/[[:blank:]]* ' ${filename}_backup '] | awk ' begin{fs= ': "}{print" > "End.txt" #合并两个文件, final.txt each line is/*xx....\n....xx*/the start and start line numbers for this type of comment paste " Start.txt "End.txt" > "final.txt" while read line do #得到起始行 start= ' echo ' $line | awk ' begin{fs= ' \ t '}{print $} ' #得到结束行 end= ' echo ' $line | awk ' begin{fs= ' \ T "}{print $}" #这里有一个bug, AS/* and/* in/*xxxx*/, in the same line, and there is code in the same line # printf ("Hello world\n"); /* Print String */#/* Print string/#上Face two kinds of situation can not judge, hope everybody optimizes if [$START-eq $END];then continue fi #删除/* to all Sed-i "${start},${end}d" "${filename}_backu" P "Done <" final.txt "Wc-l" ${filename}_backup "rm-f" Final.txt "" Start.txt "" End.txt "

Scripts can only achieve the approximate number of lines of code statistics, can not do accurate statistics!
Because there are not many tests to do, and I do not rule out some of the more rare comments I did not consider the efficiency of the script is also relatively poor, with a lot of TMP files.
So I hope you can make a lot of comments!

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.