Want to count the number of lines after the first line


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Want to count the number of lines after the first line
# 1  
Old 06-24-2013
Want to count the number of lines after the first line

hi,

How can i count the number of lines after the first line in a flat file in unix?

Say i have a flat file with a header like:
Student Name Student ID ....

Tnx
# 2  
Old 06-24-2013
So you want the total number of line minus one:

Code:
expr $(wc -l <filename) - 1

# 3  
Old 06-24-2013
this is giving me a syntax error.
Code:
$ cnt=`expr $(wc -l <REGIN) -1`
expr: syntax error


Last edited by Franklin52; 06-24-2013 at 05:16 AM.. Reason: code tags
# 4  
Old 06-24-2013
try..

Code:
 
awk 'END{print NR-1}' filename

# 5  
Old 06-24-2013
If your shell does not support the $( ... ) syntax, split up the command in two steps:

Code:
num=`wc -l <REGIN`
cnt=`expr $num - 1`

Make also sure, there is a blank before and after the minus sign in the expr command!
# 6  
Old 06-24-2013
here is my solution:

Code:
tot_cnt=$((`cat filename | wc -l`  -1 ))

# 7  
Old 06-24-2013
Quote:
Originally Posted by reignangel2003
here is my solution:

Code:
tot_cnt=$((`cat filename | wc -l`  -1 ))

This may not help you with huge files.!!
Code:
tot_cnt=$( expr $(wc -l filename) - 1 )

Make sure that you give spaces properly
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count the pipes "|" in line and delete line if count greter then number.

Hello, I have been working on Awk/sed one liner which counts the number of occurrences of '|' in pipe separated lines of file and delete the line from files if count exceeds "17". i.e need to get records having exact 17 pipe separated fields(no more or less) currently i have below : awk... (1 Reply)
Discussion started by: ketanraut
1 Replies

2. Shell Programming and Scripting

Shell script to count number of ~ from each line and compare with next line

Hi, I have created one shell script in which it will count number of "~" tilda charactors from each line of the file.But the problem is that i need to count each line count individually, that means. if line one contains 14 "~"s and line two contains 15 "~"s then it should give an error msg.each... (3 Replies)
Discussion started by: Ganesh Khandare
3 Replies

3. Shell Programming and Scripting

count number of lines between two tag

Hi I have a big xml file of having many data </Data> </Node> <Node> List <abc>3932590983 3396003964 3355713230</abc> </Data> </Node> </Data> </Node> <abc>3932590983 3396003964</abc>I want to count the lines present betweem tag starting with abc and ending with abc so o/p will be... (8 Replies)
Discussion started by: aaysa123
8 Replies

4. UNIX for Dummies Questions & Answers

Comparing two files and count number of lines that match

Hello all, I always found help for my problems using the search option, but this time my request is too specific. I have two files that I want to compare. File1 is the index and File2 contains the data: File1: chr1 protein_coding exon 500 600 . + . gene_id "20532";... (0 Replies)
Discussion started by: DerSeb
0 Replies

5. Shell Programming and Scripting

Count the number of lines in a file with one condition

Hi Everyone, 1.txt Mon 08 Feb 2010 12:30:44 AM MYT;1265560244;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:46 AM MYT;1265560246;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:48 AM MYT;1265560248;e164:0000116047275464;T;Central;0; Mon 08 Feb 2010 12:30:50 AM... (1 Reply)
Discussion started by: jimmy_y
1 Replies

6. Shell Programming and Scripting

count the number of lines that start with the number

I have a file with contents similar to this. abcd 1234 4567 7666 jdjdjd 89289 9382 92 jksdj 9823 298 I want to write a shell script which count the number of lines that start with the number (disregard the lines starting with alphabets) (1 Reply)
Discussion started by: grajp002
1 Replies

7. UNIX for Dummies Questions & Answers

Count of Number of Lines in a File

Dear Members, I want to count the number of lines in a file; for that i am using the following command : FILE_LINE_COUNT=`wc -l $INT_IN/$RAW_FILE_NAME` if i do an echo on FILE_LINE_COUNT then i get 241 /home/data/testfile.txt I don't want the directory path to be displayed. Variable... (1 Reply)
Discussion started by: sandeep_1105
1 Replies

8. Programming

to count the number of commented lines in a file

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

9. Shell Programming and Scripting

Appending line number to each line and getting total number of lines

Hello, I need help in appending the line number of each line to the file and also to get the total number of lines. Can somebody please help me. I have a file say: abc def ccc ddd ffff The output should be: Instance1=abc Instance2=def Instance3=ccc Instance4=ddd Instance5=ffff ... (2 Replies)
Discussion started by: chiru_h
2 Replies

10. Shell Programming and Scripting

Count number of lines in Binary file

Hi Friends Please help me out to count number of lines in binary file. It gives some wrong(less) using wc -l. Is there any other way to count lines of binary file. Thanks. (3 Replies)
Discussion started by: vanand420
3 Replies
Login or Register to Ask a Question