05-23-2007
How to count lines - ignoring blank lines and commented lines
What is the command to count lines in a files, but ignore blank lines and commented lines?
I have a file with 4 sections in it, and I want each section to be counted, not including the blank lines and comments... and then totalled at the end.
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, for your help!
10 More Discussions You Might Find Interesting
1. Programming
can someone guide me how to have a C pgm to count the number of commented lines? (3 Replies)
Discussion started by: naan
3 Replies
2. Shell Programming and Scripting
Hi friends, I am working on a perl script to count the commented lines, blank lines and source lines separately. Let me know if you have one. For example i have a file containing the lines:
/**
* SOURCE CODE
*/
public class SessionConstants {
/**
* Code for Session created
*/... (4 Replies)
Discussion started by: nmattam
4 Replies
3. Shell Programming and Scripting
Hi,
I'm not a expert in shell programming, so i've come here to take help from u gurus.
I'm trying to tailor a csv file that i got to make it work for the LOAD FROM command.
I've a datatable csv of the below format -
--in file format
xx,xx,xx ,xx , , , , ,,xx,
xxxx,, ,, xxx,... (11 Replies)
Discussion started by: dvah
11 Replies
4. Shell Programming and Scripting
Hi,
Consider a file named "testfile"
The contents of file are as below
first line added for test
second line added for test
third line added for test
fourth line added for test
fifth line added for test (5 Replies)
Discussion started by: anil8103
5 Replies
5. Shell Programming and Scripting
Hi.. I'm facing a trouble in replacing two blank lines in a file using shell script...
I used sed to search a line and insert two blank lines after the searchd line using the following sed command.
sed "/data/{G;G;}/" filename . In the file, after data tag, two lines got inserted blank lines..... (4 Replies)
Discussion started by: arjun_arippa
4 Replies
6. Shell Programming and Scripting
I have a file like
blah
blah blah blah
this is the text I need,
which might be between 1-4 lines, but
always has a blank line above and below
it, and is at the end of the text file
the code tags don't show the trailing blank line. I started by deleting the last blank line with:
... (2 Replies)
Discussion started by: unclecameron
2 Replies
7. UNIX for Dummies Questions & Answers
So the tag for this forum says all newbies welcome...
All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed.
Here's what I did come up with though:
... (2 Replies)
Discussion started by: Golpette
2 Replies
8. Shell Programming and Scripting
Hello All,
I have a file with data as below. Each line consists of 21 fields. I am not able to load them back to the database.
50733339,"834","834 ","005010X279A1","N","Y","007977163","0001 ",30,"2110D ","EB ","EB007 ","2 ","Conditional Required Data Element Miss
ing... (3 Replies)
Discussion started by: Praveenkulkarni
3 Replies
9. Shell Programming and Scripting
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 need to collapse duplicate lines ignoring column 1 and add values of duplicate lines (col1) so it will look like this:
col1 col2 col3 col4 col5
27 xxx 38 aaa ttt ... (3 Replies)
Discussion started by: coppuca
3 Replies
10. UNIX for Beginners Questions & Answers
Hi all,
I'm looking for a way (sed or awk) to delete multiple lines between 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
unifdef(1) General Commands Manual unifdef(1)
NAME
unifdef - remove preprocessor lines
SYNOPSIS
sym] sym] sym] sym]] ... [file]
DESCRIPTION
simulates some of the actions of in interpreting C language preprocessor command lines (see cpp(1)). For a valid preprocessor command line
contains as its first character a and one of the following keywords: or The character and its associated keyword must appear on the same
line, but they can be separated by spaces, tabs, and commented text. When appropriate, the portions of code surrounded by and including
the targeted preprocessor directives are removed, and the resultant text is written to the standard output.
Unlike does not insert included files, interpret macros, or strip comment lines. This means, among other things, that and macros occurring
within the input text are not interpreted.
Since is language-independent, it can be used for processing source files for languages other than the C language. For example, can be
used on FORTRAN language source files, provided the C language preprocessor commands are used.
Options
recognizes the following command-line options:
Complement the normal behavior by printing only the rejected lines.
Ignore text delimited by
sym. In other words, text that would otherwise be affected by some action is not touched when found within the context
of a preprocessor command using sym.
Ignore text delimited by
sym.
Replace rejected lines with blank lines
in the text written to the standard output.
Treat the input source as plain text.
C-language comment and quoting constructs are not recognized.
Define symbol
sym.
Cause symbol
sym to be undefined.
RETURN VALUE
The command returns the following exit values:
0 Output is an exact copy of the input.
1 Output is not an exact copy of the input.
2 The command fails. The failure might be due to a premature EOF or to an inappropriate or
EXAMPLES
Assume file contains the following:
The command sequence:
produces the following result in file
WARNINGS
Any symbol name defined in the file must be specified in the command line; otherwise, will ignore the line.
AUTHOR
was developed in the public domain.
SEE ALSO
cpp(1).
unifdef(1)