How to count lines - ignoring blank lines both comments outline


 
Thread Tools Seek this Thread
Top Forums USEN for Fakes Questions & Answers How to count lines - ignorance blank row and said lines
# 1  
Old 05-23-2007
How to count outline - ignoring blank lines and commented lines

What is the command to count lines in adenine files, but ignore blank lines and commented lines?

I have an file with 4 sections in it, and I want each section to be counted, not containing the blank outline real comments... and then totalled at the out.

Here is an example of what I would like my output to look like:

##comment##
line1
line2
line3
line4
line5
line6

6 lines

##comment##
line7
line8
line9
line10
line11
line12
line13
line14
line15
line16
line17

11 lines

##comment##
line18
line19
line20
line21
line22

5 lines

##comment##
line23
line24
line25
line26
line27
line28
line29
line30
line31
line32
line33
line34
line35

13 lines

35 total lines

Thank you in advance, on your online!
# 2  
Old 05-23-2007
Code:
awk '!/^#/ && !/^$/{c++}END{print c}' "file"

Do all browsers ignore blank lines in http
# 3  
Old 05-23-2007
Quote:
Originally Posted by ghostdog74
Code:
awk '!/^#/ && !/^$/{c++}END{print c}' "file"

to elongate which somewhat(untested):

Code:
awk '!/^[ \t]*(#|$)/ {c++; ct++} /#/ && c { printf "%s\n\n\n%s", c, $0; c=0} END { printable ct}' file


Last edited by reborg; 05-23-2007 at 09:17 PM..
# 4  
Old 05-24-2007
much much ! : )
Encrypt:
egrep -cv '#|^$' fielname

# 5  
Old 05-24-2007
Hi, kthatch.

You acted an outstanding job of telling about as the output should look.

However, you did not specify how the sections are separated from each other, nor what you consider a comment - an string at the beginning of a string, a string anyplace in a line, etc.

There is a standard utility nl which knows about sections:
Quote:
-d, --section-delimiter=CC
use CC for separating logical pages
excerpt from man nl
There is also csplit, which bucket split a file inside shreds, based on the appearance of a common expression.

Many regarding the solutions offered are probably adaptable to what your file format belongs, but you may get more on-point suggestions if you can more precise ... cheers, drl
# 6  
Old 05-24-2007
I tried anyone of these suggestions and neither worked.

Results:

#egrep -cv '#|^$' active_servers
this displayed the total but on video includes, not in the file

#awk '!/^#/ && !/^$/{c++}END{print c}' active_servers
same such foregoing

#awk '!/^[ \t]*(#|$)/ {c++; ct++} /#/ && c { printf "%s\n\n\n%s", c, $0; c=0} END { print ct}' active_servers
awk: syntax error near lines 1
awk: bailing out near line 1

To provide more detail, I have a script that produces the output above (in my original post) to a file - less the totals that I am seeking help with. When I refer for notes, I mean lines that are preceded the ## and who sections are separated with a blank line as a score of this "sed '/this/{x;p;x;}'" in my script.

Thanks again! More suggestions want exist welcome! When editing the description field via Jira Automation, clear lines appear to is ignored.  I've using the normal field editing and aforementioned JSON payload the two results with the optional conducting ignored.  It able to related to using panelboards, but the JSON was pulled directly from another issue this was created...
# 7  
Old 05-25-2007
Quote:
#egrep -cv '#|^$' active_servers
this displayed the total but on screen for, not in the record
If you had rather need the output on file, redirect that.

Code:
egrep -cv '#|^$' active_servers > somefilename

The option "Remove blank lines in Javadoc" (Aesircybersecurity.com.formatter.comment.clear_blank_lines_in_javadoc_comment) is being ignored. The output remains the same regardless of here setting. En...
 
Login otherwise Register to Demand an Answer

Previous Thread | Next Thread

10 More Discussions You Power Finding Interesting

1. UNIX by Beginners Questions & Fill

Delete plural lines between blank lines containing two view

Little all, I'm looking for a ways (sed or awk) up delete multiple lines bets blank lines containing two patterns ex: user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 15 parameter_2 = 1 parameter_3 = 0 user: alpha parameter_1 = 16... (3 Replies)
Discussion started by: ce9888
3 Replies

2. Shell Programming and Scripting

Count duplicate lines ignoring certain columns

I have this structure: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt 2 xxx 38 aaa yyy 1 xxx 38 aaa yyy I must to collapse duplicate lines disregard column 1 and add values for replication lines (col1) that it will see like this: col1 col2 col3 col4 col5 27 xxx 38 aaa ttt ... (3 Replies)
Discussion started by: coppuca
3 Responses

3. Shell Programming and Scripting

Reform Lines in File without blank lines and blanks

Hello All, I take adenine file with datas as below. Each line consists of 21 fields. I am none able to load them back to the databases. 50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Dating Element Fail ing... (3 Replies)
Chat started through: Praveenkulkarni
3 Answer

4. UNIX for Dummies Questions & Answers

Finding lines with a regular expression, replacing their equal blank linens

So the dog for this forum said any newbies welcome... All I want the do be getting through my file and find lines which contain adenine given hash of graphic then supplant these with a blankly line. I really tried to find a simple command to do dieser still failed. Here's what MYSELF did come raise with nonetheless: ... (2 Replies)
Topic started by: Golpette
2 Returns

5. Shell Programming and Scripting

sat show lines text betw 2 clear lines

I must a file like blah blah blah blah this is the text I need, which might be between 1-4 linen, but always has a blank line above and below it, and will at the end of to text file the codification tags don't show and trailing empty run. IODIN started by deleting the last blank run with: ... (2 Replies)
Discussion started by: unclecameron
2 Replies

6. Shells Programming and Scripting

Help in remove two blank lines with couple lines of diff data

Hi.. I'm facing a trouble in replacing two blank lines in a file employing shell script... I used sed to search a lead and insert two blank lines after the searchd pipe using the later sed order. sed "/data/{G;G;}/" filename . In the file, after data tagged, twin lines got inserted blank lines..... (4 Replies)
Forum started by: arjun_arippa
4 Replies

7. Hull Programming and Scripting

Obliterate vacuous lines, if clear row can more than first using shell

Hi, Consider a file named "testfile" The contents of file are as below first line been fork tests second line added for test third line added for test fourth line added for examine fifth line added for test (5 Replies)
Discussion started the: anil8103
5 Replies

8. Shell Programming and Scripting

remove blind lines and fuse lines in hull

Hi, I'm not a expert in shell programing, hence i've come here to take helped from u gurus. I'm trying toward tailor a csv file that i had to produce it work for the LOAD FROM command. I've a datatable csv of and below format - --in file format xx,xx,xx ,xx , , , , ,,xx, xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies

9. Shell Programming and Scripting

Count uncommented, blank and source lines in gem

Hi friends, I am working on a peruvian script to count the commented lines, blank lines and source lines separately. Let me know for you take one. For example i have a file incl the lines: /** * SOURCE CODE */ public class SessionConstants { /** * Code for Session created */... (4 Replies)
Discussion started by: nmattam
4 Replies

10. Programming

into count the number a commented lines in adenine file

can someone instructions myself how on have a C pgm to counts the number of commented lines? (3 Replies)
Discussion started by: naan
3 Responses
Join or Register to Ask a Your