PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

I have AIX so I can't use rename hopeing for something easier but I need to find all the files in the directory and then any of them that have a .err on them I need to be able to rename them back all the way to the .das

So I need to go from

PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

to

PQPZ3.DATR.QRL.R9529.D090295.T19501.das

When I have many .err's one quick script to rename them all back to the .das

I tried something like this but it just adds a .das at the end of the whole file...

for i in *.das; do mv "$i" `basename $i`.das; done

You have to use either ksh (zsh) or bash to do this - ie., a modern shell with pattern matching.

cd /path/to/files
find . -name '*.err' |\
while read file
do
	tmp=${file%%.das*}
	mv $file "$file".das
done

Test it somewhere first!

This just added the .das at the end of the .err I need something to remove it all the way back tot he .das

PQPZ3.DATR.QRL.R9529.D090295.T19501.das.1333332287722.1.2.err

to

PQPZ3.DATR.QRL.R9529.D090295.T19501.das

Change mv $file "$file".das to mv $file ${tmp}.das . It was just a typo.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.