Extracting text between two patterns 1 and 2 and pattern2 should be second occurrence of the file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extracting text between two patterns 1 and 2 and pattern2 should be second occurrence of the file
Prev   Next
# 1  
Old 08-16-2011
Extracting text between two patterns 1 and 2 and pattern2 should be second occurrence of the file

Hi All,
I have a small query. I have a file containing the following lines

File 1:
29-Jul-2011 [pattern1] GMT Static data requires update <Extraction should start here>
-----------
-----------
----------[pattern2]----------
-----------------------
-----------[pattern2] <should stop here>


Pattern1 will be time and pattern2 will be some userid:XYZ

I am trying to use following script, but it stops after the first occurrence of pattern2
awk ' /08:48:17/ { flag=1; } /gangii87/{ print $0; flag=0;} flag { print $0 }' log


Thanks
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Extracting lines from a text file based on another text file with line numbers

Hi, I am trying to extract lines from a text file given a text file containing line numbers to be extracted from the first file. How do I go about doing this? Thanks! (1 Reply)
Discussion started by: evelibertine
1 Replies

2. Shell Programming and Scripting

Adding text to the end of the specific line in a file(only to the first occurrence of it)

Hi, I want to add a text to the end of the specific line in a file. Now my file looks like this: 999 111 222 333 111 444 I want to add the string " 555" to the end of the first line contaning 111. Moreover, I want to insert a newline after this line containg the "000" string. The... (8 Replies)
Discussion started by: wenclu
8 Replies

3. Shell Programming and Scripting

Extracting a set of patterns from the text file

Hi experts, I need a help in extracting a set of patterns from the text file. Below is my scenario. Input file: I need to extract the data between My output should be as Thanks, Kalai (7 Replies)
Discussion started by: kalpeer
7 Replies

4. Shell Programming and Scripting

Append text to line if begins with pattern1 AND does not end with pattern2

Hello, I'm looking for sed solution to change ... <li>keyword</li> <li>keyword <li>keyword</li> <li>keyword <li>keyword</li> ... to ... <li>keyword</li> <li>keyword</li> <li>keyword</li> <li>keyword</li> <li>keyword</li> ... I.e., if lines beginning with <li> do not end with... (3 Replies)
Discussion started by: pioavi
3 Replies

5. Shell Programming and Scripting

[Solved] Sed/awk print between patterns the first occurrence

Guys, I am trying the following: i have a log file of a webbap which logs in the following pattern: 2011-08-14 21:10:04,535 blablabla ERROR blablabla bla bla bla bla 2011-08-14 21:10:04,535 blablabla ERROR blablabla bla bla bla ... (6 Replies)
Discussion started by: ppolianidis
6 Replies

6. Shell Programming and Scripting

Sed/awk print between different patterns the first occurrence

Thanks for the help yesterday. I have a little modification today, I am trying the following: i have a log file of a webbap which logs in the following pattern: 2011-08-14 21:10:04,535 blablabla ERROR Exception1 blablabla bla bla bla bla 2011-08-14... (2 Replies)
Discussion started by: ppolianidis
2 Replies

7. UNIX for Dummies Questions & Answers

Locating and Extracting Specific Patterns from a file

Hi all, 1. I have a file that is getting continously refreshed (appended) I want to grep all the strings containing substring of the type abcdf123@aaa.xxx.yyy.zzz:portnumber: where, before @, any letters or numbers combination, after @, IP address then symbol : then port... (4 Replies)
Discussion started by: kokoras
4 Replies

8. Shell Programming and Scripting

Sed Help.To Search Between Pattern1 And Pattern2 Containing Certain Text

Hi, Here is a sample of my Test File $ cat TestFile1 Prompt Table DQZ_ALTER_SCHEMA_ID; ALTER TABLE DQZ.DQZ_ALTER_SCHEMA_ID MONITORING; ALTER TABLE DQZ.DQZ_ALTER_SCHEMA_ID STORAGE ( NEXT 3464K ); Prompt Table DQZ_ALTER_SCHEMA_ID; ALTER TABLE DQZ.DQZ_ALTER_SCHEMA_ID MOVE LOB... (16 Replies)
Discussion started by: rajan_san
16 Replies

9. Shell Programming and Scripting

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 Started adfa fadfa... (8 Replies)
Discussion started by: rvz
8 Replies

10. UNIX for Dummies Questions & Answers

delete string in a text file leaving the first occurrence

Hi, How can i delete the second and subsequent occurrence of a particular string from a file ? eg) test.txt cattle bat battle mat matter cattle cattle my output file should be cattle bat battle mat matter (12 Replies)
Discussion started by: gopskrish
12 Replies
Login or Register to Ask a Question
REGEXP_TABLE(5) 						File Formats Manual						   REGEXP_TABLE(5)

NAME
regexp_table - format of Postfix regular expression tables SYNOPSIS
regexp:/etc/postfix/filename DESCRIPTION
The Postfix mail system uses optional tables for address rewriting or mail routing. These tables are usually in dbm or db format. Alterna- tively, lookup tables can be specified in POSIX regular expression form. To find out what types of lookup tables your Postfix system supports use the postconf -m command. The general form of a Postfix regular expression table is: pattern result When pattern matches a search string, use the corresponding result. blank lines and comments Empty lines and whitespace-only lines are ignored, as are lines whose first non-whitespace character is a `#'. multi-line text A logical line starts with non-whitespace text. A line that starts with whitespace continues a logical line. pattern1!pattern2 result Matches pattern1 but not pattern2. Each pattern is a regular expression enclosed by a pair of delimiters. The regular expression syntax is described in re_format(7). The expression delimiter can be any character, except whitespace or characters that have special meaning (traditionally the forward slash is used). The regular expression can contain whitespace. By default, matching is case-insensitive, although following the second slash with an `i' flag will reverse this. Other flags are `x' (dis- able extended expression syntax), and `m' (enable multi-line mode). Each pattern is applied to the entire lookup key string. Depending on the application, that string is an entire client hostname, an entire client IP address, or an entire mail address. Thus, no parent domain or parent network search is done, and user@domain mail addresses are not broken up into their user and domain constituent parts, nor is user+foo broken up into user and foo. Patterns are applied in the order as specified in the table, until a pattern is found that matches the search string. Substitution of substrings from the matched expression into the result string is possible using $1, $2, etc.. The macros in the result string may need to be written as ${n} or $(n) if they aren't followed by whitespace. EXAMPLE SMTPD ACCESS MAP
# Disallow sender-specified routing. This is a must if you relay mail # for other domains. /[%!@].*[%!@]/ 550 Sender-specified routing rejected # Postmaster is OK, that way they can talk to us about how to fix # their problem. /^postmaster@/ OK # Protect your outgoing majordomo exploders /^(.*)-outgoing@(.*)$/!/^owner-/ 550 Use ${1}@${2} instead EXAMPLE HEADER FILTER MAP
# These were once common in junk mail. /^Subject: make money fast/ REJECT /^To: friend@public.com/ REJECT SEE ALSO
pcre_table(5) format of PCRE tables AUTHOR(S) The regexp table lookup code was originally written by: LaMont Jones lamont@hp.com That code was based on the PCRE dictionary contributed by: Andrew McNamara andrewm@connect.com.au connect.com.au Pty. Ltd. Level 3, 213 Miller St North Sydney, NSW, Australia Adopted and adapted by: Wietse Venema IBM T.J. Watson Research P.O. Box 704 Yorktown Heights, NY 10598, USA REGEXP_TABLE(5)