Re: How to display n rows before and after grep ?
From: Michael Heiming (michael+USENET_at_www.heiming.de)
Date: 02/23/05
- Previous message: fmarchioni_at_libero.it: "How to display n rows before and after grep ?"
- In reply to: fmarchioni_at_libero.it: "How to display n rows before and after grep ?"
- Next in thread: fmarchioni_at_libero.it: "Re: How to display n rows before and after grep ?"
- Reply: fmarchioni_at_libero.it: "Re: How to display n rows before and after grep ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 23 Feb 2005 11:24:28 +0100
In comp.unix.shell fmarchioni@libero.it:
> Hi all,
> with most Linux distributions I can use
> grep -n or
> grep -C
> to display n rows -before and after- the lines intercepted by grep.
No, those switches have another meaning in GNU grep, you probably
mean "-A"/"-B".
> Unfortunately I cannot find this option on Solaris.
> (I'm using SunOS ultra450 5.8 Generic_108528-27 sun4u sparc
> SUNW,Ultra-4)
> Does anybody know an hack to achieve it, anyway ?
> (egrep, fgrep ... ?)
You can install GNU grep on Solaris, there should be ready to
install packages from Sun available (sunfreeware.com or so).
Alternatively 'ex' should work:
ex -s file <<_HERE_
/match/-3;+3p
q
_HERE_
Or use awk (Perhaps nawk, the awk in $PATH on solaris is
unusable, but there are two others available and mostly
installed)
awk '/match/ {k=4} k {k--;print}' file
Or use 'sed':
sed -n '/string/{N;N;N;N;p;}' file
-- Michael Heiming (X-PGP-Sig > GPG-Key ID: EDD27B94) mail: echo zvpunry@urvzvat.qr | perl -pe 'y/a-z/n-za-m/' #bofh excuse 224: Jan 9 16:41:27 huber su: 'su root' succeeded for .... on /dev/pts/1
- Previous message: fmarchioni_at_libero.it: "How to display n rows before and after grep ?"
- In reply to: fmarchioni_at_libero.it: "How to display n rows before and after grep ?"
- Next in thread: fmarchioni_at_libero.it: "Re: How to display n rows before and after grep ?"
- Reply: fmarchioni_at_libero.it: "Re: How to display n rows before and after grep ?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|