http://qs321.pair.com?node_id=743174


in reply to Automatically Rewrite Shebang Line on Multiple Files

This is very easy if you've got cygwin to give you a working shell, find and xargs. For example, to change from /usr/bin/perl to /usr/local/bin/perl I'd do something like (untested):

find -name '*.pl' -o -name '*.cgi' | xargs perl -pi -e "s{^#!/usr/bin/perl}{#!/usr/local/bin/perl}"

The -pi command-line switch tells Perl to do in-place editing and the -e specifies the code to on each line. If your filenames might have spaces in them you can add -print0 to the find call and -0 to the xargs call before perl.

If you want to do it all in Perl can use File::Find or something similar to find the files for you.

-sam