Would like to print 3 lines after a regular expression is found in the logfile
I would like to print 3 lines after a regular expression is found in the logfile. I'm using the following code:
The above code things works fine,but sometimes gives erroneous results. In my case i'm searching for the expression X104 in the logfile. Sometimes X104 will contain only 1 line to print and after printing that .It also prints the next 3 lines after that, e.g:
(i)11/02/09 02:21:15 X104
Text : Unable to unlink/erase file
System Error Number: 13 (d) - The data is invalid.
(ii) Text : X104 disabled.
(iii) 11/03/09 01:01:03 web200
Text : Freespace on C: is at a critical level (694.55MB).
Text : X104 enabled per scheduled_reboot.
NSLOOKUP was successful. Please reload your
configuration.
(i) : I get the desired results, regexp is found and the next 3 lines are printed
(ii) : regexp is matched (contains only 1 line) and printed, but I receive the next 3 lines (including the newline) which I find not useful for me.
Can anyone help me out
Last edited by Franklin52; 08-06-2011 at 05:49 PM..
Reason: Please use code tags for data and code samples, thank you
Using a regular expression, I would like multiple lines to be matched.
By default, a period (.) matches any character except newline. However, (?s) and /s modifiers are supposed to force . to accept a newline and to match any character including a newline.
However, the following two perl... (4 Replies)
So the tag for this forum says all newbies welcome...
All I want to do is go through my file and find lines which contain a given string of characters then replace these with a blank line. I really tried to find a simple command to do this but failed.
Here's what I did come up with though:
... (2 Replies)
I have a very large file (over 700 million lines) that has some lines that I need to delete. An example of 5 lines of the file:
HS4_80:8:2303:19153:193032 153 k80:138891
HS4_80:8:2105:5544:43174 89 k88:81949
165 k88:81949 323 0 * = 323 0 ... (6 Replies)
Hi all,
How am I read a file, find the match regular expression and overwrite to the same files.
open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat";
open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat";
while (<DESTINATION_FILE>)
{
# print... (1 Reply)
Hello,
How to print the field separator in awk? please see the following code:
cat a.txt
a 1s 2s 3s 4s
b 2s 4s
$ awk 'BEGIN{FS==" "} {print $2 $3 }' te
1s2s
2s4s
I want to get the following output :
1s 2s
2s 4s
How to realize this ?
$ cat te
a 1s,,2s 3s ... (11 Replies)
Hey, I found a way to print the lines which is just before a regular expression, not including the expression.
sed -n '/regexp/{n;p;}' myfile
Now I'm looking for a way to print all lines, exept the regular expression and also the line before the same regular expression.
Use code tags. (1 Reply)
Hi All,
I have file.txt with contents like this:
random text
To: recipient@email.co.uk
<HTML>S7randomtext more random text
random text
To: recip@smtpemail.com
<HTML>E5randomtext more random text
random text
I need the output to look like this:
1,,,1,S7
1,,,1,E5
My code so... (9 Replies)
I am trying to use regular expression to identify ONLY the commands that hasn't the word "tablespace" within it. a command starts with "create table" and ends with ; (semicolon)
example file:
create table first tablespace ;
create table second
(
BBL_CUSTOMER_NAME VARCHAR2(32),
a... (7 Replies)