################################################### ## ## Perl Helpers - Useful for setting up Perl environment ## ################################################### (Perl with a "-e" allows Perl to work on command line) perl -e "print \"@INC\"" TO USE CPAN on RedHat family linux: yum install bind-utils yum install perl perl-devel gcc curl dnf install perl-CPAN yum install expect yum install bind-utils To get Expect from CPAN: cpan App::cpanminus cpanm Term::ReadKey cpanm Net::SSH::Expect COMMAND LINE PERL CHANGING A STRING in MULTIPLE TEXT FILES IN DIRECTORY For all files in this directory, change internal variable $REPLACEMENT to $REPLACEMENT ALSO rename the original files to .original perl -i.original -pe 's/\$REPLACEMENT/\$REPLACEMENT/g' * Same as above but without retaining the original files: perl -i -pe 's/\$REPLACEMENT/\$REPLACMENT/g' * The -p means to enclose your Perl program in a print loop that looks SOMEWHAT like this: while ($_ = <>) { print "$_"; } SPECIAL CASE: remove hat-em (^M) and replace it with regular carriage return: perl -i -pe 's/^M/\n/g' filename or for all files in current directory perl -i -pe 's/^M/\n/g' * * to create the "hat-em" you need to press Ctrl-v and then Ctrl-m or Ctrl-v, m And while we are at it, this sed command on command line will remove null charactors from files: sed -i 's/\x0//g' filename.txt Remember to diff your original and replacement files to make sure the outcome is what you expected.... OOOOOPPPPPSSS!!!!! What do you do if you made a mistake? simple mkdir REVERT_ME cp -a *.original REVERT_ME cd REVERT_ME # rename files from .original to perl -e 'while(<*.original>){$_=~/(.*)\.original/; rename$_,$1}' Now, just replace the files in the original subdirectory with the files in the REVERT_ME subdirectory.