Jerry M. Howell II wrote: > hello all, > > I'm just beginning to work with sed in shell scripts I was > wondering if anyone has a simmilar script in perl they can send my > way or what the perl equivelent of the sed /s would be. Here is the > coresponding shell script if it'll help you understand what I'm > trying to acomplish. > > #!/bin/sh > > # Need some information from you > > echo "what word or string are we looking for?" > read old > echo "" > echo "what do you wish to replace it with" > read new > for script in * > do > sed 's/'$old'/'$new'/g' <$script> outfile
The perl equivalent is very similar: perl -pe "s/$old/$new/g" $script >outfile > mv outfile $script > done > > sometimes this script works and sometimes it just clears the file out > leaving it empty. I need a viable alternative but don't even know > where to start. Thanks for any help you can give me. The problem is that you're not checking to see if the sed (or perl) was successful. If you supply a bogus pattern to sed for example, outfile will be empty. You then overwrite the input file with the (now empty) file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>