Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

pull - a command line pipe-line building aid to pull perl regexps out of piped input

by cider (Acolyte)
on Sep 26, 2001 at 22:32 UTC ( [id://114901]=sourcecode: print w/replies, xml ) Need Help??
Category:
Author/Contact Info cider@compulsion.org || http://compulsion.org
Description: pull is a quick and dirty tool for building command line pipelines on pulled regular expressions, i reccomend that you protect your match strings behind single quotations, feel free to use anything regexp related for your pulled information. For example, if you wanted all of the files in your home directory that were perl scripts, you could type file * | grep "perl script" | pull '^(.*?):' or something similar of that nature. Meant to aid in pulling out the text you're really interested in.
#!/usr/bin/perl
# meant to be a pipe to aid in data pipeline building
# example: file * | grep "perl script" | pull '^(\w+)'
# or.....  file * | grep "perl script" | pull '^(.*?):'

$match = shift || die "match what?\n";

while(<STDIN>) {
 chomp;
 if (/$match/i) {
  print $1 . "\n";
 }
}
  • Comment on pull - a command line pipe-line building aid to pull perl regexps out of piped input
  • Download Code
Replies are listed 'Best First'.
Re: pull - a command line pipe-line building aid to pull perl regexps out of piped input
by John M. Dlugosz (Monsignor) on Sep 27, 2001 at 07:55 UTC
    Why does grep (or tcgrep) "not do that easily"? Ah, that it prints only the match, not the whole line? If tcgrep doesn't already do that, I think you'd be well served to add that feature to tcgrep!

    This can be done right from the Perl -e command line using the -n flag. example:  pull '^(\w+)' is simply perl -ne 'print "$1\n" if /^(\w+)/"

      I'm quite proud of the ability to do it from a single usable command in a english resembling namespace. Others of its nature off the top of my head which I find useful when hacking at text manipulation and quick pipeline building is:
      "before", # pipe, print all text on line before given regexp
      "after", # pipe, print all text on line plus str after given regexp
      "and", # pipe, print all text and append string after line
      "between", # pipe, print text between regexp1 and regexp2
      "match", # pipe, print any line matching regexp
      "exclude", # pipe, print any line not matching regexp
      "matchand", # pipe, print any line matching regexp w/and
      "matchbefore", # pipe, print any line matching regexp w/before
      all of which are available here.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: sourcecode [id://114901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2024-04-25 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found