Renaming multiple files

I have a bunch of files txt1.csv--2008 thru to txt3.csv--2008.

If i wanted to rename these files all at the same time to txt*.csv-2008 what would be the best way to do it...

Just need to get rid of the extra - in each file name.. not all files are going to be called txt*.csv--2008. Just using this as an example..

Using .ksh btw on AIX 5.3 ...

for i in txt*.csv-2008;do echo mv $i ${i//--/-};done

If works as expected, remove the echo.

tried that but get an error...

${i//--/-}: bad substitution

for i in txt*.csv-2008;do mv $i `echo $i | sed 's/--/-/'`;done

Thanks Summer,
thats worked perfectly...

My bad :slight_smile: typo.

for i in txt*.csv--2008;do echo mv $i ${i//--/-};done

hi I have a directory with files names like ABC20090101AXY.txt, ABC20090102BZ.txt,ABC20090101COF.txt etc. The digits in the filenames represent the date. I want to rename the files to AXY.txt, BZ.txt and COF.txt

I tried with this code.

myfile= date '+ABC%Y%m%d'
for i in *.txt
do
mv $i `echo $i | sed 's/$myfile//'`
done

But its giving message

mv: ABC20090101AXY.txt and ABC20090101AXY.txt are identical

Can u help me finding the problem.

Regards,
Shekhar