I have files whose filenames are in format ddmmyyyyTEXT.txt

I want to rename all the files to yyyy-mm-dd-TEXT.txt

Here, TEXT is some arbitrary text.

What sed expression I should use ??

  • 3
    Take a look at rename. – Cyrus Oct 14 '14 at 9:23
FILE="23022014hello world.txt"
mv "$FILE" "$(echo "$FILE" | sed 's/\([0-9]\{2\}\)\([0-9]\{2\}\)\([0-9]\{4\}\)\(.*\)/\3-\2-\1-\4/')"

It cuts the first 2 numbers, second 2 numbers, next 4 numbers and remaining characters separately and arranges according to your requirement

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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