![]() |
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 |
| Getting the lines between last occurrence of two patterns | rvz | Shell Programming and Scripting | 8 | 08-08-2008 05:32 PM |
| get the value between 2 patterns | minifish | Shell Programming and Scripting | 11 | 04-07-2008 02:18 PM |
| how to grep for lines between 2 give patterns? | melanie_pfefer | Shell Programming and Scripting | 1 | 04-03-2008 11:38 AM |
| How to count lines - ignoring blank lines and commented lines | kthatch | UNIX for Dummies Questions & Answers | 6 | 05-25-2007 01:21 AM |
| search patterns | rochitsharma | Shell Programming and Scripting | 1 | 02-27-2006 04:14 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
How to get lines in between Patterns?
Hi,
I need to create a script that does the following: 1. Read the file for the occurrences of "EXECUTE" and "END" strings. There will be several occurrences of EXECUTE and END strings on the file. 2. The resulting lines in #1, needs to be searched for the word "Error|failed|error|warning", if the word error occurs on the line, prints the specific line and 1 line above it. Here's a sample input file: HTML Code:
-------------------------------< EXECUTE >---------------------------- This session consists of: Feature R-state Install-type Upgrade-from ------------------------------------------------------------------------ conf_system R3C01 upgrade R3B03 ------------------------------------------------------------------------ ------------------< CIF(conf) 2008-04-08 02:31:28 >-------------------- ----------------------< END 2008-04-08 02:31:57 >--------------------- -------------------------------< EXECUTE >----------------------------- ---------< FM(fm_core,fmba,fmaa,fmx,fmav) 2008-04-08 03:14:09 >------- [main] Error installing feature [fmx] - com.er.nm.if.ist.NoMatchingUpgradeClauseFoundException: --------------------------< END 2008-04-08 03:22:51 >------------------ The output should be: HTML Code:
---------< FM(fm_core,fmba,fmaa,fmx,fmav) 2008-04-08 03:14:09 >-------
[main] Error installing feature [fmx] - com.er.nm.if.ist.NoMatchingUpgradeClauseFoundException:
I'm not familiar with awk command, and if you can guide me on this please? Any help is greatly appreciated. //racbern |
|
||||
|
try this
#! /usr/bin/ksh cat linebetween.d | awk ' /EXECUTE/ { start = 1; nextline=1; continue } /END/ { start = 0 ; continue} (/Error/ || /failed/ || /error/ || /warning/) && start == 1 { print hesderline; print $0 } { if (nextline == 1 ) {hesderline = $0; nextline=0}} ' |
|
||||
|
Hi aju_kup,
Thanks for your quick reply. I tried your suggestion, and it only prints the lines with the patterns "Error|failed|error|warning". I need to get also the line above it. I did some trial and error of the awk command and come out with the following (but I dont know how to get the line above it): # awk '/EXECUTE/,/END/ { if ($0 ~ /Error installing/) print $0}' /var/tmp/llsva.log //racbern |
|
||||
|
The cat is useless, of course, and you can combine all those search expressions into one big ole regular expression:
Code:
awk '/EXECUTE/ { start = 1; continue }
/END/ { start = 0; continue }
start && /[Ee]rror|failed|warning/ { print pline; print }
{ pline = $0 }' file
|
|
||||
|
Hi era,
Thanks for reply as well. I added == 1 on your suggestion, and it worked fine as well. awk '/EXECUTE/ { start = 1; continue } /END/ { start = 0; continue } start == 1 && /[Ee]rror|failed|warning/ { print pline; print } { pline = $0 }' file Is there a way I can assign the pline to a variable, so that I can manipulate it afterwards? Thanks again.. //racbern |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|