Java Mailing List Archive

http://www.dba.5341.com/

Home » Home (12/2007) » oracle l »

RE: HP-UX 11/grep

Jared Still

2004-02-05


nothing wrong with the perl.
You might consider getting gnu grep though.

grep -3 string file

This will display the 3 lines before/after the target string.






STEVE OLLIG <sollig@(protected)>
Sent by: oracle-l-bounce@(protected)
02/05/2004 10:58 AM
Please respond to oracle-l


    To:   "'oracle-l@(protected)>
    cc:
    Subject:     RE: HP-UX 11/grep


your fond memories are of the VMS command search/window=n

i also needed something similar on solaris recently and resorted to a
simple
perl script. i also considered awk.

hopefully Jared won't laugh at my admitted rusty perl skills. the code
below finds a line containing "string" in /path/file and will print that
line and the one following to stdout. granted it could easily be more
re-usable and window lines on both sides of "string" like the old VMS
command did, but i was in a hurry and had a very specific application for
this...

<snip>
#!/bin/perl -w

use strict;

my $log_file = '/path/file';
my $printnext = 'no';

open(LOG, "<$log_file") or die "Couldn't open file $log_file: $!";

while (<LOG>) {
if ( $printnext eq "yes" ) {
  print("$_\n");
}
$printnext = 'no';
if ( /string/ ) {
  print("$_\n");
  $printnext = 'yes';
}
}
close(LOG) or die "Couldn't close file $log_file: $!";
</snip>

-----Original Message-----
From: Vergara, Michael (TEM) [mailto:mvergara@(protected)]
Sent: Thursday, February 05, 2004 12:43 PM
To: Oracle-L (E-mail)
Subject: OT: HP-UX 11/grep


Hi Gang...sorry about being kinda OT...but...

A long time ago, when I used VMS, I could scan a file and see
a set number of lines before and after the line I was looking=20
for. I don't even remember the command nowadays.

Does anyone know of an analogous command that can be used in the
*NIX environment?

Thanks,
Mike

---
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=

Michael P. Vergara
Oracle DBA
Guidant Corporation

----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to: oracle-l-request@(protected)
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------
----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to: oracle-l-request@(protected)
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------




----------------------------------------------------------------
Please see the official ORACLE-L FAQ: http://www.orafaq.com
----------------------------------------------------------------
To unsubscribe send email to: oracle-l-request@(protected)
put 'unsubscribe' in the subject line.
--
Archives are at http://www.freelists.org/archives/oracle-l/
FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html
-----------------------------------------------------------------


©2008 dba.5341.com - Jax Systems, LLC, U.S.A.