Re: grep

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



Scott McClanahan wrote:
grep out the next 5 lines after the first and only instance

The scope of grep's view of the world is a single line. At any one time, it knows nothing more.

If you need to deal with multiple lines, I suggest perl.  Untested code:

#!/usr/bin/perl
while (<>) {
	if (m/bar/) {
		for ($i = 0; $i < 5 and defined($_); ++$i) {
			print;
			$_ = <>;
		}
		last;
	}
}
_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux