Release new version 2.13.0
[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 ################################################################################
7
8 ################################################################################
9 # Usage-Examples taken from:
10 # http://groups.google.de/groups?selm=87acw742ea.fsf%40swangoose.isst.fhg.de
11
12 # get ipaddress of interface ppp0:
13 # $ ifconfig ppp0 | grepc 'inet addr:(.*?)\s'
14
15 # list all debian packages which have dependency on a given package
16 # $ apt-cache showpkg perl-tk | grepc '(.*?),perl-tk'
17
18 # list all files which have been changed in comparison to the
19 # cvs repository:
20 # $ cvs diff 2>/dev/null | grepc '^RCS file: (.*?),v$'
21
22 # get environment variable of a specific process:
23 # $ grepc 'PATH=(.*?)\0' </proc/<pid>/environ
24
25 # list destination ports of iptables lol:
26 # $ </var/log/messages grepc 'DPT=(.*?) '
27
28 # get debian packages on host1, download them on host2:
29 # host1:$ apt-get install --yes --force-yes --print-uris gnome >uris.txt
30 # host2:$ <uris.txt grepc "^'(.*?)'" | xargs -l ncftpget
31
32 # list all directories containing apache-java source:
33 # $ find . -path '*org/apache/*.java' | grepc '^(.*?)/org/apache' | sort | uniq
34 ################################################################################
35
36 my $re = shift or die "usage: grepc <perl regexp containing a capture buffer>\n";
37
38 $re = eval { qr/$re/ } or die "invalid regexp: $@";
39
40 while (<>) {
41     if (/$re/) {
42         print "$1\n";
43     }
44 }
45
46 ## END OF FILE #################################################################