0

I'm using HP UX and I have 1000 files that are all 10 characters long and are all numbers.

I would like to put an underscore in the file name after the 4th number to make an 11 digit file name.

i.e 1234567890 to 1234_567890.

What would be the best way to do this ?

I haven't really attempted much as I don't know the best way to tackle it and have very limited unix rename knowledge.

2 Answers 2

0

I usually do something along these lines with bash:

find . -type f | while read f
do 
    mv "$f" "${f:0:4}_${f:4}"
done
Sign up to request clarification or add additional context in comments.

Comments

0

You can use the sed command

find . -type f -name "??????????" | while read f
do
    mv "$f" "$(echo $f | sed 's/^\(....\)/\1_/')"
done

2 Comments

Is that a standard HP-UX tool? On linux it's an optional Perl extension.
Hi, this seems to work. I then had to change it as we also have 14 character number files so changed to mv "$f" "$(echo $f | sed 's/^(......)/\1_/')".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.