Sponsored Content
Top Forums Shell Programming and Scripting Extracting text between two patterns 1 and 2 and pattern2 should be second occurrence of the file Post 302547829 by gangii87 on Tuesday 16th of August 2011 05:18:33 PM
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
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
dbutil(1)							Mail Avenger 0.8.3							 dbutil(1)

NAME
dbutil - database utility SYNOPSIS
dbutil {-d | --dump} dbfile dbutil {-q | --query} [-t] dbfile key dbutil {-u | --update} [-n] dbfile key [value] dbutil {-x | --delete} dbfile key dbutil -t [date | [+|-]interval] DESCRIPTION
The dbutil program maintains a database of key-value pairs that can be queried and updated from the command line. For each such pair in the database, it also keeps an expiration time, so that unused entries can be purged from the database. dbutil must be given an option specifying in which mode to run the program. The following modes are available: --dump (-d) Prints the contents of the database. Each database entry is printed in one of the the following two formats, depending on whether the record has an expiration time: key value key value (expiration-time) --query (-q) Prints the value of a particular key in the database. If the -t flag is also specified, prints the expiration time of the record. In addition, the --expire flag can be specified to update the expiration time on the record. Exits 0 if the key was found, 1 if the key was not in the database, or 2 if there is a system error. --update (-u) Sets the value of a key in the database to a particular value. If no value is supplied, sets the value to the empty string (which is not the same as deleting the record). The --expire flag can also be specified to set an expiration time on the record. Ordinarily, this option overwrites any previous value in the database. If the -n option is supplied, dbutil will not overwrite a previously stored value in the database (and will not update the expiration time on the record). Exits 0 if the key was found, 1 if -n was specified and the key was already in the database, or 2 if there is a system error. --expire={date | [+|-]interval} This option can be specified in conjunction with --update or --query to set an expiration time on the record. The option has two formats. You can either specify an absolute time, as the number of seconds since Jan 1, 1970 GMT, or you can specify an offset from the current time with the format: [+|-]countunits Where + means in the future, - means in the past, count is a number, and units is one of the following characters: s - seconds m - minutes h - hours D - days W - weeks M - months Y - years For example --expire=+36D means the record will be deleted in 36 days. If you always look up key with the command: dbutil --query --expire=+36D key then the key will only expire if you do not look it up within 36 days. Note that dbutil keeps a sorted list of the records by time of last access. Thus, purging old records is not an inherently expensive operation, and happens automatically whenever you modify the database. --nosync (-N) Ordinarily, dbutil synchronously flushes the database file to disk after making any modifications, to minimize the window of vulnerability in which a crash could corrupt the database (if the --dbhome option is not supplied). Synchronously flushing the database file is slow, however. This option suppresses that behavior, and can be used to build lookup tables efficiently. For example, you might have a script that builds a file x.db by issuing the following commands: #!/bin/sh -e rm -f x.db~ dbutil -Nu x.db~ key1 val1 dbutil -Nu x.db~ key2 val2 # ... dbutil -Nu x.db~ keyn valn dbutil -u @ @ mv -f x.db~ x.db --delete (-x) Deletes a particular key from the database (if the database contains the key). Exits 0 if the key was found, 1 if the key was not in the database, or 2 if there was a system error. -t [date|interval] With no options, prints the number of seconds since Jan 1, 1970, GMT. With an argument that takes the same format as --expire, prints the expiration time as an absolute number of seconds since 1970. Not really a database function, but useful hen you want to store a timestamp in the database. Note that -t can also be combined with the --query option, in which case it causes dbutil to print the expiration time of the key, rather than its value. dbutil attempts to minimize the damage from an inopportune crash by flushing the database file to disk whenever it is modified. However, there is still a small window in which your database can be irrevocably corrupted. This may be alright if you are just using the database to store "soft state". If you want the database to be recoverable under any circumstances, you must use write-ahead logging, in which case dbutil needs to keep a directory with database logs, not just a single database file. The following option specifies where to keep the log files. It must be used in conjunction with the other options for each mode except -t: --dbhome=dbhome Specifies that database log files should be kept in directory dbhome (which will be created if it does not already exist). Note that database files with relative pathnames will also be stored in this directory. It is highly recommended that you use relative pathnames so as to store database files and log files together. Otherwise, you run the risk of accessing a logged database without the --dbhome option and trashing its contents. ENVIRONMENT
DB_HOME When set, specifies a directory in which to keep log files, so as to make the database crash-recoverable. This is equivalent to specifying the option --dbhome=$DB_HOME (except that any actual --dbhome argument will override the environment variable). SEE ALSO
avenger(1) The Mail Avenger home page: <http://www.mailavenger.org/>. BUGS
If you do not use the --dbhome option or DB_HOME environment variable and your machine crashes at the wrong time, you can lose your whole database. The --dbhome may or may not work if the directory is stored on NFS; it depends on the NFS implementation. If you access the database from multiple machines simultaneously, you will likely corrupt the database. Accessing from multiple processes on one machine is fine, because dbutil does locking. If you ever access the same database file with and without the --dbhome option (or DB_HOME), you will probably irrevocably trash it. For that reason, databases with relative pathnames are actually stored in the log directory. AUTHOR
David Mazieres Mail Avenger 0.8.3 2012-04-05 dbutil(1)
All times are GMT -4. The time now is 12:22 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy