Projects / kgrep

kgrep

kgrep searches through a file or files for a specified pattern and displays the target line containing the pattern as well as a certain number of lines on either side of the target line. GNU grep can do this with the -A, -B and -C switches, and other platform-specific grep implementations may have similar functionality. The main advantage to kgrep is that it's small and can be easily used on any system that has Perl5 installed, rather than going through the hassle of installing a different grep binary (this is actually what the author uses it for most often).

Tags
Licenses
Operating Systems
Implementation

Recent releases

  •  09 Sep 2003 05:44

    Release Notes: This version features a minor code and documentation cleanup.

    •  30 Oct 1999 03:02

      Release Notes: Initial public release.

      Recent comments

      24 Nov 2003 12:55 reboot2

      Why kgrep?

      > Yes, GNU grep is available on most Linux systems, but in my experience, it's often not installed on the proprietary systems I use (which happen to include Perl5 with some regularity). I sometimes find it easier to install a small Perl script than build and install GNU grep on those machines.

      If that is the main purpose I would make that the main point in the description. Don't describe what grep does, because probably anyone knows that. Describe why one would want to install kgrep instead of grep, when no grep is available.


      When I read the description i thought "grep can do that too, it is in perl, so what, i don't need it". Maybe that is only my opinion, but what I probably should have though is "hey, if i ever need a grep and have perl installed, i can use kgrep".

      24 Nov 2003 11:10 pronovic

      Re: GNU grep

      > GNU grep can do that too with -A and -B
      > switches. You should really update the
      > description of the tools with some good
      > reasons why it is superior to the
      > standard grep that is probably available
      > on any system.

      I admit to missing the -A and -B options in the GNU grep manpage. Yes, these options are equivalent to kgrep's -n option.

      Incidentally, I never said that the tool was "superior" to GNU grep or any other grep. I just said "some of this functionality may be duplicated in some versions of grep, but the script is still useful and will work on any machine which has Perl5 installed".

      Yes, GNU grep is available on most Linux systems, but in my experience, it's often not installed on the proprietary systems I use (which happen to include Perl5 with some regularity). I sometimes find it easier to install a small Perl script than build and install GNU grep on those machines.

      So, there's no need to update the description. It's accurate as it stands. Unless there's something specific in the description that you think is wrong? (I agree that my response to the -C question was incorrect.)

      24 Nov 2003 10:38 reboot2

      Re: GNU grep

      > > Doesn't GNU grep do this with -C ?
      %
      > Roughly, but not quite. You can't ask GNU grep to give you a different number of lines of context above and below a given match. So, 'grep -C 2' (to get two lines of context above and below) is equivalent to 'kgrep -n 2' or 'kgrep -n 2,2', but kgrep also allows 'kgrep -n 1,2' or 'kgrep -n 0,5' (to get, respectively, one line above and two below, or no lines above and five below).

      GNU grep can do that too with -A and -B switches. You should really update the description of the tools with some good reasons why it is superior to the standard grep that is probably available on any system.

      09 Sep 2003 08:29 pronovic

      Re: GNU grep

      > Doesn't GNU grep do this with -C ?


      Roughly, but not quite. You can't ask GNU grep to give you a different number of lines of context above and below a given match. So, 'grep -C 2' (to get two lines of context above and below) is equivalent to 'kgrep -n 2' or 'kgrep -n 2,2', but kgrep also allows 'kgrep -n 1,2' or 'kgrep -n 0,5' (to get, respectively, one line above and two below, or no lines above and five below).

      Besides, the description of the project does say, "Some of this functionality may be duplicated in some versions of grep, but the script is still useful and will work on any machine which has Perl5 installed." :-)

      09 Sep 2003 01:42 akhill

      GNU grep
      Doesn't GNU grep do this with -C ?

      Screenshot

      Project Spotlight

      OpenStack4j

      A Fluent OpenStack client API for Java.

      Screenshot

      Project Spotlight

      TurnKey TWiki Appliance

      A TWiki appliance that is easy to use and lightweight.