Can grep show the matching lines and the next N lines after a match? For instance, I have a config file wit hthe following text: [Tag h1] foreground=#2e5a03 underline=double indent=0 weight=PANGO_WEIGHT_BOLD scale=2.25 I would ideally grep on "[Tag h1]" and have grep display the match and the next 5 lines so that I see all the content of the h1 section. Can this be done? Thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com
Pintér Tibor
2011-May-30 21:13 UTC
[CentOS] Grep: show me this line and the next N lines?
On 05/30/2011 11:08 PM, Dotan Cohen wrote:> Can grep show the matching lines and the next N lines after a match? > For instance, I have a config file wit hthe following text: > [Tag h1] > foreground=#2e5a03 > underline=double > indent=0 > weight=PANGO_WEIGHT_BOLD > scale=2.25 > > I would ideally grep on "[Tag h1]" and have grep display the match and > the next 5 lines so that I see all the content of the h1 section. > > Can this be done? > > Thanks! >man grep hint: A t
Ljubomir Ljubojevic
2011-May-30 21:14 UTC
[CentOS] Grep: show me this line and the next N lines?
Dotan Cohen wrote:> Can grep show the matching lines and the next N lines after a match? > For instance, I have a config file wit hthe following text: > [Tag h1] > foreground=#2e5a03 > underline=double > indent=0 > weight=PANGO_WEIGHT_BOLD > scale=2.25 > > I would ideally grep on "[Tag h1]" and have grep display the match and > the next 5 lines so that I see all the content of the h1 section. > > Can this be done? > > Thanks! >man grep says "-A 5" would give you matching line + 5 more. Ljubomir
Meenoo Shivdasani
2011-May-30 21:15 UTC
[CentOS] Grep: show me this line and the next N lines?
On Mon, May 30, 2011 at 5:08 PM, Dotan Cohen <dotancohen at gmail.com> wrote:> Can grep show the matching lines and the next N lines after a match? >> I would ideally grep on "[Tag h1]" and have grep display the match and > the next 5 lines so that I see all the content of the h1 section. >Try grep -A 5 pattern filename M -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20110530/b00378b1/attachment-0005.html>
John R. Dennison
2011-May-30 21:15 UTC
[CentOS] Grep: show me this line and the next N lines?
On Tue, May 31, 2011 at 12:08:37AM +0300, Dotan Cohen wrote:> > Can this be done?"man grep" - I think you will be surprised when you take a look at it. John -- Worrying works. About 90% of the things I worry about never happen. -- Woody Paige (1946-), sports columnist, on ESPN's "Around the Horn" -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available URL: <http://lists.centos.org/pipermail/centos/attachments/20110530/dd39acc2/attachment-0005.sig>
Thanks, all. I did actually look at the grep manpage but after a few screenfuls it became tl;dr and I started just skimming. I suppose that I skimmed too fast! Thanks! -- Dotan Cohen http://gibberish.co.il http://what-is-what.com
Kenneth Porter
2011-Jun-07 02:26 UTC
[CentOS] Grep: show me this line and the next N lines?
--On Tuesday, May 31, 2011 1:08 AM +0300 Dotan Cohen <dotancohen at gmail.com> wrote:> Can grep show the matching lines and the next N lines after a match?If I'm just inspecting a file I use less and the "/" command to search up to the next occurrence of a regular expression. Use the "?" command to search backwards. See the man page for less for lots more options.
On Tue, Jun 7, 2011 at 05:26, Kenneth Porter <shiva at sewingwitch.com> wrote:> --On Tuesday, May 31, 2011 1:08 AM +0300 Dotan Cohen <dotancohen at gmail.com> > wrote: > >> Can grep show the matching lines and the next N lines after a match? > > If I'm just inspecting a file I use less and the "/" command to search up > to the next occurrence of a regular expression. Use the "?" command to > search backwards. See the man page for less for lots more options. >Thanks, Kenneth. I am familiar with the VIM keybindingsin less and man. I need something scriptable though. -- Dotan Cohen http://gibberish.co.il http://what-is-what.com