#!/usr/bin/perl # # Author: rasterboy # Email: raster@zymm.com # Web: http://rasterweb.net/raster/ # Date: 12.23.1998 # # Description: stringer is a simple script that reads in a text file and lets you # either save or delete every line that contains the string you enter. # # License: This software is licensed under the GNU General Public License. # A copy of the GNU GPL can be found at: http://www.gnu.org/copyleft/gpl.txt # This software is open source. This software is free software. ##################################################### # This line might be a little MacPerl-centric # You can change it to call the script in whatever way # suits you best on your operating system of choice... die ("Please drop a file on the applet.\n") unless ($ARGV[0]); ##################################################### # Get some input from the user print "What string would you like to scan for? "; $string = ; chop ($string); ##################################################### # Check if we're going to save lines or delete them do { print "Would you like to save or delete these lines? "; $sd = ; chop ($sd); } until (($sd eq "s") or ($sd eq "d")); ##################################################### # Open the input and output files open (FILE, "<$ARGV[0]"); open (OUTPUT, ">$ARGV[0].out"); if ($sd eq "s") { &save; } elsif ($sd eq "d") { &delete; } ##################################################### # Close the input and output files close (OUTPUT); close (FILE); print "\nDone!\n"; ##################################################### # The 'save the lines' subroutine sub save { while ( ) { if ($_ =~ /$string/gi) { print OUTPUT $_; } } } ##################################################### # The 'delete the lines' subroutine sub delete { while ( ) { if ($_ !~ /$string/gi) { print OUTPUT $_; } } } # END