|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Display blocks containing specific pattern
Hi, I have a file containing multiple entries. Each block starts with <BEGIN and ends with <END. Sample data is given below Code:
<BEGIN
IMSI=095001202630;
MSISDN=00145132916;
DEFCALL=TS11;
CURRENTNAM=BOTH;
CAT=COMMON;
TBS=TS11&TS12&TS21&TS22;
CARDTYPE=SIM;
VLRLIST=200;
CLIPOC=NO;
LCS=1;
OCSI=131;
TCSI=88;
UCSI=28;
SUBRES=ALLPLMN;
SUB_AGE=0;
UPL_TIME=1340536017;
GPRSUPL_TIME=1339578803;
CHARGE_GLOBAL=NONE;
<END
<BEGIN
IMSI=095001202630;
MSISDN=00145132916;
DEFCALL=TS11;
CURRENTNAM=BOTH;
CAT=COMMON;
TBS=TS11&TS12&TS21&TS22;
CARDTYPE=SIM;
VLRLIST=200;
CLIPOC=NO;
LCS=1;
OCSI=131;
SUBRES=ALLPLMN;
SUB_AGE=0;
UPL_TIME=1340536017;
GPRSUPL_TIME=1339578803;
CHARGE_GLOBAL=NONE;
<ENDI want to display all lines b/w <BEGIN and <END if OCSI=131 and TCSI= field is not present. In above data, result should be second block as OCSI is 131 and TCSI field is not present. I can get the all lines b/w BEGIN and END using sed but at loss on how to proceed further. Thanks Last edited by Scrutinizer; 07-05-2012 at 07:44 PM.. Reason: quote tags -> code tags |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Code:
sed -n '/<BEGIN/,/<END/{
H
/<END/{
s/.*//
x
/\n *TCSI=/! {
/\n *OCSI=131.\n/ {
s/^\n//
p
}
}
}
}' inputfile |
| Sponsored Links | ||
|
|
#3
|
||||
|
||||
|
You can try this in gawk Code:
awk 'BEGIN {RS="<BEGIN"} $0 !~ /TCSI=/ && /OCSI=131/ { print RS $0 } ' |
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to Detect Specific Pattern and Print the Specific String after It? | radynaraya | UNIX for Dummies Questions & Answers | 3 | 06-13-2012 09:31 AM |
| how to split this file into blocks and then send these blocks as input to the tool called Yices? | paramad | Shell Programming and Scripting | 5 | 12-17-2010 01:35 AM |
| Convert 512-blocks to 4k blocks | rockycj | UNIX for Dummies Questions & Answers | 2 | 08-03-2010 06:24 PM |
| Want to grep for a pattern and display the content above that pattern | ajayakunuri | Shell Programming and Scripting | 6 | 06-25-2010 06:48 AM |
| how to display specific lines of a specific file | raidkridley | UNIX for Dummies Questions & Answers | 2 | 10-15-2008 02:46 PM |
|
|