How do I change the extensions on a slew of files

Mike Hogsett hogsett at csl.sri.com
Wed Sep 3 19:38:23 PDT 2003


> from an sh type shell
> for i in *.inc
> do
> z=`echo $i | sed -e "s/inc/htm/g"`
> mv ${i} ${z}
> done

This won't give expected results for a file named "fooinc.inc".  It will
become "foohtm.htm".  I realize that based on the file names given in the
original email this doesn't appear to be an issue, but changing the sed
command to

	  sed -e 's/\.inc$/\.html/'

may give better (more generally useful) results.  Also note the ' instead
of " so that the shell doesn't perform variable expansion within the sed
command text. The shell will ignore the $ and instead sed uses it to match
end of line or string in this case.

 - Mike






More information about the freebsd-questions mailing list