Depend on console-tools; drop runit
[grml-scripts.git] / usr_bin / grepc
1 #!/usr/bin/perl -w
2 # Filename:      grepc
3 # Purpose:       grep for pattern and cut it
4 # Authors:       Olaf Klischat <klischat@cs.tu-berlin.de>
5 # Bug-Reports:   see http://grml.org/bugs/
6 # Latest change: Fre Jän 07 10:41:17 CET 2005 [mika]
7 ################################################################################
8
9 ################################################################################
10 # Usage-Examples taken from:
11 # http://groups.google.de/groups?selm=87acw742ea.fsf%40swangoose.isst.fhg.de
12
13 # get ipaddress of interface ppp0:
14 # $ ifconfig ppp0 | grepc 'inet addr:(.*?)\s'
15
16 # list all debian packages which have dependency on a given package
17 # $ apt-cache showpkg perl-tk | grepc '(.*?),perl-tk'
18
19 # list all files which have been changed in comparison to the
20 # cvs repository:
21 # $ cvs diff 2>/dev/null | grepc '^RCS file: (.*?),v$'
22
23 # get environment variable of a specific process:
24 # $ grepc 'PATH=(.*?)\0' </proc/<pid>/environ
25
26 # list destination ports of iptables lol:
27 # $ </var/log/messages grepc 'DPT=(.*?) '
28
29 # get debian packages on host1, download them on host2:
30 # host1:$ apt-get install --yes --force-yes --print-uris gnome >uris.txt
31 # host2:$ <uris.txt grepc "^'(.*?)'" | xargs -l ncftpget
32
33 # list all directories containing apache-java source:
34 # $ find . -path '*org/apache/*.java' | grepc '^(.*?)/org/apache' | sort | uniq
35 ################################################################################
36
37 my $re = shift or die "usage: grepc <perl regexp containing a capture buffer>\n";
38
39 $re = eval { qr/$re/ } or die "invalid regexp: $@";
40
41 while (<>) {
42     if (/$re/) {
43         print "$1\n";
44     }
45 }
46
47 ## END OF FILE #################################################################