Running sed and counting number of lines processed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Running sed and counting number of lines processed
# 1  
Old 12-27-2012
Running sed and counting number of lines processed

Code:
/bin/sed -n ';4757335,$ p' | wc -l
/bin/sed -n ';4757335,$ p' | egrep "Failed" | egrep -c "PM late arrrival"


how can i combine the above two sed commands into one? i want to count the number of lines between the specified line number and the end of the file. AND and i want to count how many lines contain a specified set of strings within those lines.

i dont want to run these sed commands separately because they would add greatly to the time it takes for the script to complete.
# 2  
Old 12-27-2012
I think using awk is the best option here:
Code:
awk 'NR>4757335&&/Failed/&&/PM late arrrival/{c++}NR>4757335{d++}END{print c,d;}' filename

This User Gave Thanks to Yoda For This Post:
# 3  
Old 12-28-2012
wonderful!!! i have yet to test it, but could you please explain your beautiful awk command to me? please????
# 4  
Old 12-28-2012
SkySmart, please test it and let me know if it is giving the desired o/p, I will explain the code.
# 5  
Old 12-28-2012
Quote:
Originally Posted by bipinajith
SkySmart, please test it and let me know if it is giving the desired o/p, I will explain the code.
it works. the command returns two numbers:

Code:
35300 313306

# 6  
Old 12-28-2012
NR>4757335&&/Failed/&&/PM late arrrival/ - Lines greater than line number: 4757335 and matches pattern: Failed and matches pattern PM late arrrival

{c++} - Increment variable: c for lines that matches all 3 conditions above.

NR>4757335 - Lines greater than line number: 4757335

{d++} - Increment variable: d for lines that matches condition above.

END{print c,d;} - In the end print value of variables: c and d
This User Gave Thanks to Yoda For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines from processing

I have a file like below #Fields section bald 1234 2345 456 222 abcs dddd dddd ssss mmmm mmm mmm i need do not process a files stating with # I was written code below while read -r line do if then echo ${line} >> elif then ... (3 Replies)
Discussion started by: Chenchireddy
3 Replies

2. Shell Programming and Scripting

File lines starts with # not processed or exclude that lines

I have requirement in my every files starting lines have # needs to be not processing or exclude the that lines. I have written a code like below, but now working as expected getting ERROR" line 60: 1 #!/bin/sh 2 echo ======= LogManageri start ========== 3 4 #This directory is... (1 Reply)
Discussion started by: Chenchireddy
1 Replies

3. Shell Programming and Scripting

[Solved] Counting The Number of Lines Between Values with Multiple Variables

Hey everyone, I have a bunch of lines with values in field 4 that I am interested in. If these values are between 1 and 3 I want it to count all these values to all be counted together and then have the computer print out LOW and the number of lines with those values in between 1 and 3,... (2 Replies)
Discussion started by: VagabondGold
2 Replies

4. Shell Programming and Scripting

sed&awk: replace lines with counting numbers

Dear board, (I am trying to post this the 3rd time, seems there's some conflicts with my firefox with this forum, now use IE) ------ yes, I have searched the forum, but seems my ? is too complicated. ------------origianl file --------------- \storage\qweq\ertert\ertert\3452\&234\test.rec... (4 Replies)
Discussion started by: oUo
4 Replies

5. Shell Programming and Scripting

sed counting lines

Hi, I'm using the command: sed -n '$=' $1 on a sh script on AIX. This script is used to count the number of lines of files. If the file has no lines at all the command doesn't return nothing. I need the command to return 0 when the file has no lines at all. How can I achieve this? Best... (5 Replies)
Discussion started by: jppedroso
5 Replies

6. Shell Programming and Scripting

Deleting processed lines

I have a log file that I am processing. This contains messages from and to a server (requests and responses). The responses to requests may not be in order i.e. we can have a response to a request after several requests are sent, and in some error cases there may not be any response message. ... (2 Replies)
Discussion started by: BootComp
2 Replies

7. Shell Programming and Scripting

counting the number of lines - again

Hi all, I use bash shell and I have a problem with wc. I would like to determine the number of lines in a file so I do wc -l filename but I don't want to get the filename again I just would like to have the number of lines and use it in a variable. Can anybody help? Thank you, (7 Replies)
Discussion started by: f_o_555
7 Replies

8. Shell Programming and Scripting

awk - Counting number of similar lines

Hi All I have the input file OMAK_11. OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000002EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE 1341 OMAK 000003EXCLUDE ... (8 Replies)
Discussion started by: dhanamurthy
8 Replies

9. Linux

counting the number of lines

Hello, I have afile which begins with a few urls on multiple lines and then there is listing of some information on separate lines. The listing begins with the word Name on a given line followed by teh actual list. I want to count the number of lines in this file after the line having... (6 Replies)
Discussion started by: nayeemmz
6 Replies

10. UNIX for Dummies Questions & Answers

Counting The Number Of Duplicate Lines In a File

Hello. First time poster here. I have a huge file of IP numbers. I am trying to output only the class b of the IPs and rank them by most common and output the total # of duplicate class b's before the class b. An example is below: 12.107.1.1 12.107.9.54 12.108.3.89 12.109.109.4 12.109.6.3 ... (2 Replies)
Discussion started by: crunchtime
2 Replies
Login or Register to Ask a Question