![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get lines in between Patterns? | racbern | Shell Programming and Scripting | 11 | 04-23-2008 07:28 AM |
| how to grep for lines between 2 give patterns? | melanie_pfefer | Shell Programming and Scripting | 1 | 04-03-2008 11:38 AM |
| Replace second occurrence only | lyoncc | Shell Programming and Scripting | 5 | 12-26-2007 11:21 PM |
| awk + last occurrence | agibbs | UNIX for Dummies Questions & Answers | 2 | 10-06-2007 03:32 PM |
| Grep for the same occurrence or maybe Sed | hcclnoodles | Shell Programming and Scripting | 4 | 09-12-2002 12:25 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Getting the lines between last occurrence of two patterns
Hi
I am new shell scripting, i need help on the follwoing I have a application log file, the application is called on cron, the log includes a "started" and "finished" lines repeatedly. I need to get the log of the for the latest run of the application. Sample log file StartedIn this log how to do i get the lines between the last occurence of Started and Finished |
|
||||
|
good that you found it useful!!!
check out the man pages for tail, awk and grep to understand how it works. In particular, check the switches I've used for each command. Don't think I am being rude to you. You must have heard the good old story where the fisherman taught a starving person to fish, rather than giving him few of his catch :-) cheers maverix |
|
||||
|
Quote:
|
|
||||
|
I hope i have understood you correctly: regular expressions can be made to apply only on a limited group of lines:
Code:
sed -n '/start/,/finish/ {
p
}
To print only the last group of lines is a bit tricky: copy everything in one such group to the holdspace, overwriting it every time a new group starts. Upon reaching the last line output the hold space and you are done. Code:
sed -n '/^Finished/ {
H
}
$ {
x
p
}
/^Started/,/^Finished/ {
/^Started/ {
h
}
/^Started/ !{
H
}
}'
bakunin |
|
||||
|
Quote:
![]() |
![]() |
| Bookmarks |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|