0

Files are -

new_file.dat01,
new_file.dat02 and so on

i want to rename it as new_file_01.dat, new_file_02.dat and so on.

Any ideas on how to do it?

RavinderSingh13
  • 130,504
  • 14
  • 57
  • 93
  • 4
    Welcome to SO, please do add your efforts in form of code in your question, which is highly encouraged on SO, thank you. – RavinderSingh13 Jan 28 '21 at 17:28
  • https://unix.stackexchange.com/q/631402/13792 – choroba Jan 28 '21 at 17:43
  • @choroba the link you provided had a different renaming requirement . please read my question again, each file is to be renamed with different number – Anurag Pandey Jan 28 '21 at 17:50
  • Does this answer your question? [Rename multiple files based on pattern in Unix](https://stackoverflow.com/questions/1086502/rename-multiple-files-based-on-pattern-in-unix) – xhienne Feb 06 '21 at 00:25

1 Answers1

2

What about:

for f in *file.dat*; do mv "$f" "$(echo "$f" | sed -E 's/.dat(.*)/_\1.dat/')";done
pascal
  • 1,036
  • 5
  • 15