Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I want to rename the below files, such that the first 4 chars and last 7 chars are removed, the remaining chars to be converted to decimal, while rename.

Example if the filename is 0030002345678.txt, should be renamed to 00.txt(removing the chars and converting to hex).

If it is 00300A2345678.txt, should be renamed to 10.txt(after conversion from hex of '0A'

share|improve this question

1 Answer 1

up vote 1 down vote accepted

What about this:

ls | python -c 'import sys, os; print len([os.system("mv %s %02i.%s" % (name[:-1], int(name.split(".")[0][4:-7], 16), name.split(".")[1])) for name in sys.stdin])'

Assumes the files to be renamed are exactly those that ls would print; supply anything more relevant, if this is not the case.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.