🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1126

Re: How to do mv *.xyz *.abc in shell script??

#1126
From: Jim Rogers
Date: Mon, 10 Sep 1990 17:09
50 lines
1471 bytes
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
Technical Details
Message-ID: <27620002@hp-lsd.COS.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpfcso!hpldola!hp-lsd!jimr
References: <5569@minyos.xx.rmit.oz>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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