Path: utzoo!attcan!uunet!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpldola!hp-lsd!jimr From: jimr@hp-lsd.COS.HP.COM (Jim Rogers) Newsgroups: comp.unix.shell Subject: Re: How to do mv *.xyz *.abc in shell script?? Message-ID: <27620002@hp-lsd.COS.HP.COM> Date: 10 Sep 90 17:09:46 GMT References: <5569@minyos.xx.rmit.oz> Organization: HP Logic Systems Division - ColoSpgs, CO Lines: 50 Following is a ksh script which I find useful for this purpose: #!/bin/ksh # This script changes the ending patterns in a set of files. # The pattern to look for is described as the argument to the "-f" # option. The pattern to create is described as the argument to the "-t" # option. The script will work on the list of file names following the # options. set -- `getopt f:t: $*` if [ $? -ne 0 ] then print -u2 "Usage: $0: -f current_pattern -t new_pattern file ..." exit 1 fi old="" new="" for opt in $* do case $opt in -f) old="$2"; shift 2;; -t) new="$2"; shift 2;; --) shift; break ;; esac done if [ "$old" = "" ] then print -u2 "Error $0: Must specify an ending pattern to change." exit 2 fi for file in $* do prefix=${file%$old} if [ "$prefix" != "$file" ] then newfile="$prefix""$new" mv "$file" "$newfile" fi done ------------------------------------------------------------------------------- Jim Rogers Logic Systems Division Hewlett Packard Company