![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | 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 here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to get lines in between Patterns? | racbern | Shell Programming and Scripting | 11 | 04-23-2008 04:28 AM |
| how to grep for lines between 2 give patterns? | melanie_pfefer | Shell Programming and Scripting | 1 | 04-03-2008 08:38 AM |
| Replace second occurrence only | lyoncc | Shell Programming and Scripting | 5 | 12-26-2007 07:21 PM |
| awk + last occurrence | agibbs | UNIX for Dummies Questions & Answers | 2 | 10-06-2007 12:32 PM |
| Grep for the same occurrence or maybe Sed | hcclnoodles | Shell Programming and Scripting | 4 | 09-11-2002 09:25 PM |
|
|
Submit Tools | LinkBack | Thread Tools | 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 |
| Forum Sponsor | ||
|
|
|
|||
|
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 |
|
|||
|
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:
|
|
|||
|
Quote:
|
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|