#!/usr/bin/perl # @(#) cutgrep V1.0 cuts the regular expression from the file # Author: Shankar Chakkere (shankara@erols.com) # Date: 25 Nov 1996 # Status: Working # Abstract: This script will cut the regular expression from each line of the # file # Usage: cutgrep regexp filename # History: Mar 02 1998 # Added option -v to verify which portion will be cut by printing both the # unmodified line and the modified line. The modified line will be enclosed # within $encloser # Copyright (C) 1999 Shankar Chakkere # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # Visit http://www.fsf.org for more information ######################################################################## $debug = 0; $encloser = '**'; ($#ARGV < 0 ) && &usage; # $#ARGV -1 when no command line parameter $verify = 0; while ($ARGV[0] =~ m/^-/) { $_= shift(@ARGV); print "$_\n" if $debug; s/^-//; while (s/^.//) { if ($& eq 'v') { $verify = 1; } else { &badusage("Unknown option \-$&\n"); } } } #while ($ARGV[0] =~ m/^-/) $pattern = $ARGV[0]; open(FILE, $ARGV[1]) || die "Can't open input file : $ARGV[0] . $!"; while () { chop($_); if( /$pattern/) { if( $verify ) { print "$_\n" if $verify; print "$encloser $ $ $encloser\n"; # $` = line before match , # $& = pattern matched } else { print "$ $\n"; # $` = line before match , # $& = pattern matched # $' = rest of line after match # space inbetween$` and $' is needed } } else # print all line if no match found { print "$_\n"; } } close FILE; sub usage { die <