Computing.Net > Forums > Unix > Fetching specific lines from a file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Fetching specific lines from a file

Reply to Message Icon

Name: sandeeprk
Date: May 5, 2003 at 04:24:45 Pacific
OS: UNIX
CPU/Ram: p2
Comment:

Hi all,
I have a log file with fixed patterns as shown below:-

START(prg01)


(please note prg0x)
END(prg01,success)
START(prg02)


END(prg02,success)
.... this goes on with prg03,prg04...

I need to extract cases which hav failed... here prg02 has failed. so i need 2 grep for the failures, find out the cases that have failed & then extract the lines () between start & end(only failures). Can somebody help.
Thanx in advance
sandeep



Sponsored Link
Ads by Google

Response Number 1
Name: James Boothe
Date: May 5, 2003 at 07:59:55 Pacific
Reply:

prg02 also shows success. I will assume that it was suppose to say "fail".

Following code will print each group of lines that contains the string "fail". A line beginning with "START" signals the beginning of the next group of lines.

sed -e '/^START/!{H;$!d;}' \
      -e 'x;/fail/!d;' logfile

The string "fail" found anywhere in the group will cause the group to be printed. Let me know if you want that tightened up to look only for "fail" within an END line.


0

Response Number 2
Name: sandeeprk
Date: May 5, 2003 at 21:23:05 Pacific
Reply:

Hello james,
thanx 4 the reply. prg02 should have been fail & not success. i am sorry 4 that mistake. I will just rephrase the question again ... more clearly.

1>START(prg01)
2>
3>
(please note prg0x)
4> END(prg01,success)
5>START(prg02)
6>
7>
8>
9>END(prg02,fail)
1-9 are line numbers 4 u'r convinience.
here, prg02 has failed , so i need to extract lines from 5 to 9.


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: Fetching specific lines from a file

removing specific line from file www.computing.net/answers/unix/removing-specific-line-from-file/5042.html

getting a specific line from a file www.computing.net/answers/unix/getting-a-specific-line-from-a-file/7708.html

Get the first line from a file www.computing.net/answers/unix/get-the-first-line-from-a-file/7981.html