Counting Commented lines in code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aparajita
    New Member
    • Mar 2008
    • 8

    Counting Commented lines in code

    In Pl/SQL scripts, The comments are multi lined starting from /* and ending with */.
    How can we count the commented lines if there are hundred scripts to be scanned.
    a grep command will give only the first and last line.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by aparajita
    In Pl/SQL scripts, The comments are multi lined starting from /* and ending with */.
    How can we count the commented lines if there are hundred scripts to be scanned.
    a grep command will give only the first and last line.
    Are you looking at counting total number of commented lines from a file?

    Comment

    • aparajita
      New Member
      • Mar 2008
      • 8

      #3
      yes, i am looking at counting total no of lines in a code which are commented but not from a single file...it has to be done for abt 100 PL/SQL codes....

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Originally posted by aparajita
        yes, i am looking at counting total no of lines in a code which are commented but not from a single file...it has to be done for abt 100 PL/SQL codes....
        Try this:

        1. Have a counter = 0
        2. Loop through the file, read line by line and grep for /* or *\. Say /* is in 6th Line. Then here counter = 6. Assign this calue to another variable say start_of_line = 6
        3. Then cotinue fetching and checking for /* or *\. If you find *\ in 10th line. Now counter = 10, now result=result + (counter - start_of_line)) ;
        So result = 0 + (10-6) => 4;
        4. Continue for another set of lines in the loop and keep adding to the result. Finally when you reach END OF FILE, you will have the total number of lines in the PLSQL CODE.

        Try implementing this logic and let us know in case of any issues.

        Comment

        • amitpatel66
          Recognized Expert Top Contributor
          • Mar 2007
          • 2358

          #5
          Originally posted by aparajita
          yes, i am looking at counting total no of lines in a code which are commented but not from a single file...it has to be done for abt 100 PL/SQL codes....
          If you want only the sum of total count from all the files as such, then i suggest you to concatenate all the files in to a single one and then loop through a single file. If you want the count file wise, then you need to loop through the files individually.

          Comment

          • aparajita
            New Member
            • Mar 2008
            • 8

            #6
            Yes, this is an option but using 'sed' to count the commented lines gives quite good results :)

            Comment

            • amitpatel66
              Recognized Expert Top Contributor
              • Mar 2007
              • 2358

              #7
              Originally posted by aparajita
              Yes, this is an option but using 'sed' to count the commented lines gives quite good results :)
              Thats Good!! I dont have a unix box here else I would have tried and checked it out!!

              Comment

              Working...