Thanks a mil,
Mags.
Try:
for I in *.txt
do
TARGET=`echo $I | sed 's/\.txt$/_xx.txt$/'`
mv $I $TARGET
done
--
___________________________________________________________________________
Paul R. Brandariz E-mail Internet: bran...@lore.kla-tencor.com
KLA-Tencor Corporation
One Technology Dr.
Milpitas, CA 95035
Paul Brandariz x6546 <bran...@lore.kla-tencor.com> wrote in message
news:3935348E...@lore.kla-tencor.com...
> Have a look at basename(1)
basename does not help the original poster. Reread the post, and
then read the manpage for basename.
Moshe
--
jehsom@ (angband.org, bellsouth.net, burdell.org, cc.gatech.edu,
nullity.dhs.org, polter.net, resnet.gatech.edu, treklink.net, usa.net,
wreck.org, yo.dhs.org); (gte741e, mj116) @prism.gatech.edu; ICQ 1900670
Messy, messy, messy.
Better:
#!/bin/ksh
IFS='';
typeset -r Target="$1";
if [[ ${#Target} -eq 0 ]];then
print -u2 "No file specified";
exit 1;
fi
Path="${Target%/*}";
FileName="${Target##*/}";
Name="${FileName%%.*}";
Ext="${FileName##*.}";
Newname="_xx";
typeset Oname="${Newname}.${Ext}";
mv "${Target}" "${Oname}";
if [[ $? -ne 0 ]];then
print -u2 "operation failed";
exit 1;
fi
exit 0;
> I realise that it's easy, for example, to copy/move files to the
> original filename with a new extension in /bin/sh, but I need a shell
> script that will rename the part preceding the file extension,
> i.e. mv *.txt --> *_xx.txt
> Do i need to strip the file extension first using sed maybe? (if so,
> how?)
With bash or ksh you can use the built-in pattern manipulation
capability.
Assume n="FileName.txt", then ${n%.txt} will expand to "FileName"
and you could do something like this:
$ for n in *.txt; do mv $n ${n%.txt}_xx.txt; done
> Alternatively, would mmv work - is there a Solaris version?
Yes, mmv would work: mmv '*.txt' '#1_xx.txt'
If you can't get it precompiled from Sun, you
could just grab the source from some archive and compile it yourself.
<http://www.faqs.org/faqs/unix-faq/faq/part2/>
Also have a look at man basename
HTH
--
Manfred Bartz