Get the line count from 2nd line of the file ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get the line count from 2nd line of the file ?
# 1  
Old 06-16-2008
Get the line count from 2nd line of the file ?

Hi,

I want to get the line count of the file from the 2nd line of the file ? The first line is header so want to skip that.

Thanks.
# 2  
Old 06-16-2008
Hammer & Screwdriver Not sure what in the second line of file

To see the second line of a file:

Code:
cat myfile | head -2 | tail -1

To store to a value:

Code:
myval=$(cat myfile | head -2 | tail -1)

# 3  
Old 06-16-2008
Code:
awk ' NR==2' filename

or maybe
Code:
 sed  '2,2!d' filename

# 4  
Old 06-16-2008
This is just printing the 2nd line of the file.

Actually, I want to get the count of rows in the file starting the 2nd line.


Thanks.
# 5  
Old 06-16-2008
Code:
awk 'END{print NR-1}' file

Regards
# 6  
Old 06-16-2008
Hammer & Screwdriver one less than total number of rows, thus

Since I have a file called runedit...

Code:
> linect=$(cat runedit | wc -l)
> echo $linect
508
> linect=$((linect-1))
> echo $linect
507

# 7  
Old 06-16-2008
Try using WC command. Get the total count and subtract one.Smilie
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

How to read file line by line and compare subset of 1st line with 2nd?

Hi all, I have a log file say Test.log that gets updated continuously and it has data in pipe separated format. A sample log file would look like: <date1>|<data1>|<url1>|<result1> <date2>|<data2>|<url2>|<result2> <date3>|<data3>|<url3>|<result3> <date4>|<data4>|<url4>|<result4> What I... (3 Replies)
Discussion started by: pat_pramod
3 Replies

3. Shell Programming and Scripting

Perl - line count of a file

Hi, I am quite new to perl scripting. I have a dat file (datFile) from which I am pulling only first column and saving the output to a new file (f). From that file (f) I am removing blank lines and saving it to new file (datFile1). I am able to get the count of $f file in variable $cnt. But... (4 Replies)
Discussion started by: Neethu
4 Replies

4. Shell Programming and Scripting

To take line count from a file

Hi guys, I am having a file which where i need to take line count based on searching a particular string from a list say list_file.txt which occurs in 2nd column of my main file and to take the line count which doesnot exist in list file say list_file.txt for eg: my main file looks like this... (4 Replies)
Discussion started by: rohit_shinez
4 Replies

5. UNIX for Advanced & Expert Users

How to take file line count in AIX

HI All, I am trying to take file line count in UNIX and AIX Unix command to take file line count-- working fine count=`wc -l /apps/hgford/sorted/E.testing.DLY|cut -f1 -d " "` 1355Same command when run in aix --having issue count=`wc -l /apps/hgford/sorted/E.testing.DLY|cut -f1 -d " "`... (5 Replies)
Discussion started by: Perlbaby
5 Replies

6. Shell Programming and Scripting

Count per line in txt file

In a txt file called, eso.txt, I have: ...... 3 where process_status_flag = 70 and LISTENER_ID in (930.00, 931.00, 932.00, 933.00, 934.00) 4 group by LISTENER_ID 5 order by LISTENER_ID; LISTENER COUNT ----------... (3 Replies)
Discussion started by: Daniel Gate
3 Replies

7. 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

8. Shell Programming and Scripting

[Solved] Problem in reading a file line by line till it reaches a white line

So, I want to read line-by-line a text file with unknown number of files.... So: a=1 b=1 while ; do b=`sed -n '$ap' test` a=`expr $a + 1` $here do something with b etc done the problem is that sed does not seem to recognise the $a, even when trying sed -n ' $a p' So, I cannot read... (3 Replies)
Discussion started by: hakermania
3 Replies

9. Shell Programming and Scripting

File Line Count

Hi, Came across a weird problem today. I was just trying to write this small script which would read the number of lines in a file. Depending on the count some further processing would be done. I used wc -l in order to get that done. But since it depends on the number of new line characters, if... (1 Reply)
Discussion started by: King Nothing
1 Replies

10. Shell Programming and Scripting

how to count characters by line of file ?

Hello, Member or professional need help how to count characters by line of file Example of the file is here cdr20080817164322811681txt cdr20080817164322811txt cdr20080817164322811683txt cdr20080817164322811684txt I want to count the characters by line of file . The output that I... (4 Replies)
Discussion started by: ooilinlove
4 Replies
Login or Register to Ask a Question