Help with bash command to change lots of file names

Sam Smith S at mSmith.net
Fri May 10 15:40:49 BST 2002


On Thu, 9 May 2002, greadey wrote:
> I have a directory with lots of files called CHAPN.TXT where n is a
> number from 1 to 14.  I want to turn them all into latex files and so
> for ease of editing in Vim I want to change them all to chN.tex.  I have
> been trying to write a bash command to do it with a for loop and sed and
> I basically have;
>
> for f in *
> do
> NEW=`echo $f | sed -e 's/CHAP \( \W+ \. \) /ch \1 tex/ ' ` # I've put
> whitespace in for clarity
> #mv $f $NEW
> echo $NEW
> done

for i in *.txt; do mv $i `basename $i .txt`.tex ; done
for i in *.tex; do mv $i `echo $i |tr -s CHAP ch`.tex ; done

it could be done in a single pass, but you can do that yourself :-)



Sam
-- 
  Indifference: It Takes 43 Muscles to Frown and 17 to smile, but it
      Doesn't Take Any to Just Sit There with a Dumb Look on Your Face






More information about the Ukfreebsd mailing list