RegEx - selective delete around a pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting RegEx - selective delete around a pattern
# 1  
Old 06-07-2012
RegEx - selective delete around a pattern

I need RegEx to delete text block delimited by "^--" and "^request saved" if the block contained the pattern "FAILED:No air,rail,hotel or car" in the following.

Many thanks in advance!

Code:
company_id=9292 queue_id=72 internationalOnly=0
Building XML...
ABC123
Adding passenger first=First  last=LAST
PASS_FIRST Emergency - <TravelDocumentPublisherService_v1_types.EmergencyContactType_Holder instance at 0xb7943dcc>
FAILED:No air,rail,hotel or car
point.agent.com - - [24/May/2012 18:33:18] "POST / HTTP/1.1" 200 -
request saved to requests/2012-05-24T18:33:35.970388.xml
--
company_id=6653 queue_id=534 internationalOnly=0
Building XML...
DEF459
Adding passenger first=FIRST last=LAST
FIRST LAST Emergency - <TravelDocumentPublisherService_v1_types.EmergencyContactType_Holder instance at 0xb6ea176c>
FAILED:No air,rail,hotel or car
point.agent.com - - [24/May/2012 22:42:44] "POST / HTTP/1.1" 200 -
request saved to requests/2012-05-24T22:42:44.502880.xml
--
company_=2479 queue_id=99 internationalOnly=0
Building XML...
ACE333
Adding passenger first=FIRST last=LAST
FIRST LAST Emergency - <TravelDocumentPublisherService_v1_types.EmergencyContactType_Holder instance at 0xb6e489ec>
FAILED:Segment Fault
point.agent.com - - [24/May/2012 22:48:05] "POST / HTTP/1.1" 200 -
request saved to requests/2012-05-24T22:48:11.437577.xml
--
company_id=7031 queue_id=534 internationalOnly=0
Building XML...
GAR333
Adding passenger first=FIRST last=LAST
FIRST LAST Emergency - <TravelDocumentPublisherService_v1_types.EmergencyContactType_Holder instance at 0xb797e9cc>
FAILED:SOAP Error
point.agent.com - - [24/May/2012 22:50:14] "POST / HTTP/1.1" 200 -
request saved to requests/2012-05-24T22:50:38.009576.xml
--
Building XML...
YYEE12
Adding passenger first=FIRST last=LAST
PASSFIRST LAST Emergency - <TravelDocumentPublisherService_v1_types.EmergencyContactType_Holder instance at 0xb6eb4c4c>
RAIL SEGMENT
FAILED:No air,rail,hotel or car
point.agent.com - - [25/May/2012 15:42:34] "POST / HTTP/1.1" 200 -
request saved to requests/2012-05-25T15:42:34.320824.xml


Last edited by Scrutinizer; 06-07-2012 at 06:50 PM.. Reason: code tags
# 2  
Old 06-07-2012
How about the following awk one-liner:
Code:
awk '!/FAILED:No air,rail,hotel or car/{printf (N++?RS:"") $0}' RS="--\n" infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to delete all lines before a particular pattern when the pattern is defined in a variable?

I have a file Line 1 a Line 22 Line 33 Line 1 b Line 22 Line 1 c Line 4 Line 5 I want to delete all lines before last occurrence of a line which contains something which is defined in a variable. Say a variable var contains 'Line 1', then I need the following in the output. ... (21 Replies)
Discussion started by: Soham
21 Replies

2. UNIX for Dummies Questions & Answers

Selective replace and delete

Hi My input file looks like this: >BAHMI01000090.1 Details of the shopping list 9800 item00090, whole set of listed artifacts and objects >BAHMI01050012.1 Details of the shopping list 9800 item02310, whole set of listed artifacts and objects >BAHMI01070078.1 Details of the shopping list ... (5 Replies)
Discussion started by: sonia102
5 Replies

3. Shell Programming and Scripting

PHP - Regex for matching string containing pattern but without pattern itself

The sample file: dept1: user1,user2,user3 dept2: user4,user5,user6 dept3: user7,user8,user9 I want to match by '/^dept2.*/' but don't want to have substring 'dept2:' in output. How to compose such regex? (8 Replies)
Discussion started by: urello
8 Replies

4. Shell Programming and Scripting

Only Regex pattern match help

Hi We have a tool to monitor logs in our environment. The tool accepts log pattern match only using regex and I accept I am a n00b in that:confused:. I had been banging my head to make it work without much success and at last had to turn on to my last option to post it here. I had got great... (2 Replies)
Discussion started by: radioactive9
2 Replies

5. UNIX for Dummies Questions & Answers

Selective delete in SQL

Hi All This might be a weird query but its related to deleting specific details in database. Bascially I had built a database using a set of files seq1 of 300 mb seq2 of 200 mb seq3 of 350 mb seq4 of 300 mb and after building the database i realized that i didn't need the whole data.... (6 Replies)
Discussion started by: sonia102
6 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Selective delete command

Hi All. I didnt know how to put this question as but i want to delete my values following string_X but need to retain the data in it. I hope the following might help me in conveying my doubt. My sequence looks like this. >string_1 CAJW010000001... (3 Replies)
Discussion started by: sonia102
3 Replies

7. Shell Programming and Scripting

Sed for selective pattern replacement

Hi I am having a code snippet grant permission to all user sts|ln|uSe|PSG sajncht|se|Use|PPSPSG psg|ln|use|TSPSG sts_user.Me revoke I need to change all occurance of use (uSe,Use,use) with USE. I am using the following sed command for this sed 's//USE/g' s_sample.txt Output: (7 Replies)
Discussion started by: sudeep.id
7 Replies

8. Shell Programming and Scripting

sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows. header for file 1111 2222 3333 header for file 1111 2222 3333 header for file... (8 Replies)
Discussion started by: gary_w
8 Replies

9. UNIX Desktop Questions & Answers

Trying to delete a directory pattern-selective deletion

Trying to delete a directory or a file using a pattern-selective deletion (using “*” and “?” ) (4 Replies)
Discussion started by: herberwz
4 Replies

10. Shell Programming and Scripting

comment/delete a particular pattern starting from second line of the matching pattern

Hi, I have file 1.txt with following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433 ** ** ** In file 2.txt I have the following entries as shown: 0152364|134444|10.20.30.40|015236433 0233654|122555|10.20.30.50|023365433... (4 Replies)
Discussion started by: imas
4 Replies
Login or Register to Ask a Question