[FredLUG] Re: Search/grep for a specific line

Paul W. Frields stickster at gmail.com
Mon Feb 5 22:38:22 EST 2007


On Mon, 2007-02-05 at 22:31 -0500, Peter Larsen wrote:
> Paul W. Frields wrote:
> > On Mon, 2007-02-05 at 21:37 -0500, Peter Larsen wrote:
> >> Paul W. Frields wrote:
> >>> On Mon, 2007-02-05 at 15:37 -0500, Peter Larsen wrote:
> >>>> Paul W. Frields wrote:
> >>>>> On Mon, 2007-02-05 at 15:06 -0500, Peter Larsen wrote:
> >>>>>> Does anyone know of a method to "grep" for a specific line in a file? 
> >>>>>> Even better, if it would print 3-4 lines before and after that line too?
> >>>>> You can grep "^this is the line content$" to get the whole line.  If you
> >>>>> want lines before/after, use the -B/-A switches.  HTH!
> >>>>>
> >>>> Hey - well, I have the line number, and right now I do a "less" to get 
> >>>> the line and context. But it would be nice if I could simple "grep" 
> >>>> myself to it.
> >>>>
> >>>> -B/-A switches?? That's new to me. Do you have an example?
> >>> grep -B 3 -A 3 'mysql[^-]' /etc/services
> >> Great - interesting. I'll definitely make a note of -A and -B.
> >> Could you do a grep and specify a line number instead of a pattern?
> >>
> >> My "problem" is, that a data migration going through hundreds of 
> >> thousands of lines, simply reports linenumbers when it returns 
> >> errors/problems. I need to see the actual line to get detailed 
> >> information to diagnose the issue.
> > 
> > Why not just grep for the line number at the beginning of the line?  Is
> > that the output format?  Pretty simple, e.g. for line 293:
> > 
> > grep "^293[^0-9]"
> 
> I think you misunderstand or I haven't expressed myself clearly enough.
> There are no line numbers in the file. The linenumber count is simply 
> "count cr + 1" ... in other words, it's the vi G equivilant I'm looking 
> for. Type a number, hit G and vim goes to the line number typed. 
> However, I would like to dump several areas to an output file in one go, 
> hence the need for a command line solution.

OK, I guess I'm still not following.  I think it would be easier if you
could simply give an example of the input and error/output formats
you're dealing with.  But does "grep -n" help?

-- 
Paul W. Frields, RHCE                          http://paul.frields.org/
  gpg fingerprint: 3DA6 A0AC 6D58 FEC4 0233  5906 ACDB C937 BD11 3717
       Fedora Project Board: http://fedoraproject.org/wiki/Board
    Fedora Docs Project:  http://fedoraproject.org/wiki/DocsProject
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://calypso.tux.org/pipermail/fredlug/attachments/20070205/0e215b27/attachment.bin 


More information about the Fredlug mailing list