Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: "grep -p" functionality in linux

  1. #1
    Join Date
    Dec 2008
    Location
    Taxes
    Beans
    458
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    "grep -p" functionality in linux

    I don't know if this is the right spot for this - if a moderator knows of a better forum, would you please move it?

    I learned to write korn shell scripts in AIX and the grep command there has the -p "paragraph" function/parameter. I'm sure most everyone is familiar with this, it's incredibly useful when parsing log files in scripts.

    gnu grep doesn't have this functionality, although it's been requested a number of times -- requests for this functionality usually meet a response like this: http://savannah.gnu.org/bugs/?14630#discussion

    Which are great if you are doing it as a one off command line thing, but try doing that with variables in a script and for me at least they fail miserably.


    Are there ways to reproduce this behavior in linux that I'm just dumb enough not to know about?
    Anyone interested in banding together and recreating the feature?

  2. #2
    Join Date
    Jan 2012
    Beans
    3

    Re: "grep -p" functionality in linux

    Paragrep works for me...

    http://software.clapper.org/paragrep/

    Hope it will for you.

  3. #3
    Join Date
    Dec 2008
    Location
    Taxes
    Beans
    458
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: "grep -p" functionality in linux

    Quote Originally Posted by mario.niessner View Post
    Paragrep works for me...

    http://software.clapper.org/paragrep/

    Hope it will for you.
    I can't get it installed.

    The version called by the pip and easy_install program is version 3.1.0
    That version doesn't exist at the URL where the installer is directed.
    There doesn't appear to be anyway to direct the installer to use an earlier or local version of the package.

    Any ideas?

  4. #4
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: "grep -p" functionality in linux

    Why don't you just grab the source from the git repo?
    Code:
    apt-get install git
    Code:
    git clone git://github.com/bmc/paragrep.git
    Code:
    cd paragrep
    Code:
    python setup.py install
    Last edited by rubylaser; June 22nd, 2012 at 09:56 PM.

  5. #5
    Join Date
    Dec 2008
    Location
    Taxes
    Beans
    458
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: "grep -p" functionality in linux

    Quote Originally Posted by rubylaser View Post
    Why don't you just grab the source from the git repo?
    Code:
    apt-get install git
    Code:
    git clone git://github.com/bmc/paragrep.git
    Code:
    cd paragrep
    Code:
    python setup.py install
    Working on that now.

  6. #6
    Join Date
    Dec 2008
    Location
    Taxes
    Beans
    458
    Distro
    Ubuntu Studio 12.04 Precise Pangolin

    Re: "grep -p" functionality in linux

    Quote Originally Posted by MakOwner View Post
    Working on that now.
    Code:
    Downloading http://pypi.python.org/packages/any/g/grizzled-python/grizzled-python-1.0.3.linux-x86_64.tar.gz#md5=dcd4e2506db7320d215eefcd2b16c17f
    Processing grizzled-python-1.0.3.linux-x86_64.tar.gz
    error: Couldn't find a setup script in /tmp/easy_install-epn7M4/grizzled-python-1.0.3.linux-x86_64.tar.gz
    On to other things for the day.

    This is on Centos 6.2, by the way, so no easy apt repository to use.

  7. #7
    Join Date
    Dec 2010
    Beans
    573
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: "grep -p" functionality in linux

    Quote Originally Posted by MakOwner View Post
    This is on Centos 6.2, by the way, so no easy apt repository to use.
    OK, I have to ask. Why are you posting this to a Ubuntu Server forum if you are running CentOS?

    Since I deal with both flavors of Linux you may want to try the following to install get:
    Code:
    sudo yum install get

  8. #8
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: "grep -p" functionality in linux

    Quote Originally Posted by hawkmage View Post
    OK, I have to ask. Why are you posting this to a Ubuntu Server forum if you are running CentOS?

    Since I deal with both flavors of Linux you may want to try the following to install get:
    Code:
    sudo yum install get
    I assume you mean this
    Code:
    sudo yum install git

  9. #9
    Join Date
    Jul 2010
    Location
    Michigan, USA
    Beans
    2,136
    Distro
    Ubuntu 18.04 Bionic Beaver

    Re: "grep -p" functionality in linux

    Quote Originally Posted by MakOwner View Post
    Code:
    Downloading http://pypi.python.org/packages/any/g/grizzled-python/grizzled-python-1.0.3.linux-x86_64.tar.gz#md5=dcd4e2506db7320d215eefcd2b16c17f
    Processing grizzled-python-1.0.3.linux-x86_64.tar.gz
    error: Couldn't find a setup script in /tmp/easy_install-epn7M4/grizzled-python-1.0.3.linux-x86_64.tar.gz
    On to other things for the day.

    This is on Centos 6.2, by the way, so no easy apt repository to use.
    That install script isn't working properly (I see similar errors with easy_install and the git repo). The work around for me was to install grizzled by itself, then remove the dependency from the setup.py file.

    Code:
    easy_install grizzled
    Then, remove this line from your setup.py file.
    Code:
    install_requires = ['grizzled-python>=1.0', ],
    Now, you should be able to get this working from the paragrep git download by running this again.
    Code:
    python setup.py install
    I have it working now.
    Code:
    root@test:~# paragrep 
    paragrep: error: Not enough arguments.
    Not enough arguments.
    Usage: 
    paragrep [-aiov] [-p EOP_REGEXP] [-e REGEXP] ... [-f EXP_FILE] ... [file] ...
                   -OR-
    paragrep [-iv] [-p EOP_REGEXP] regexp [file] ...
    
    Options:
      --version             show program's version number and exit
      -h, --help            Show this message and exit.
      -a, --and             Logically AND all regular expressions.
      -e regexp, --regexp=regexp, --expr=regexp
                            Specify a regular expression to find.This option may
                            be specified multiple times.
      -f exprfile, --file=exprfile
                            Specify a file full of regular expressions, one per
                            line.
      -i, --caseblind       Match without regard to case.
      -o, --or              Logically OR all regular expressions.
      -p eop_regexp, --eop=eop_regexp
                            Specify an alternate regular expression to match end-
                            of-paragraph. Default: ^\s*$
      -P, --print-eop       Print the line that marks the end of each paragraph.
                            Default: False
      -v, --negate          Negate the sense of the match.
    Hope that helps.

  10. #10
    Join Date
    Aug 2007
    Location
    Sweden
    Beans
    197
    Distro
    Xubuntu 10.04 Lucid Lynx

    Re: "grep -p" functionality in linux

    Other alternatives are awk and perl

    Code:
    awk -v RS="" -v ORS="\n\n" '/PATTERN/' [FILENAMES]
    Code:
    perl -000 -ne 'print if /PATTERN/' [FILENAMES]
    (Differs from grep in that "/" in pattern must be escaped.)

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •