try to batch rename using sed (if this is best)

hi gooday

I need some help with a rename I am attempting.
I'd like to rename a bunch of files in a folder
example

list.dat.old to list_N.dat
query.dat.old to query_N.dat
note the two periods in (.dat.old) to become _N.dat

I tried using sed like this

ls *.dat.old | sed '/.dat.old/_N.dat'

this only works in the terminal and just gives a print out of the changed names
I'd like it to actually rename the files in batch from with a script that i'd call rename.sh that i can run.

thanks

Taking what you already have:

$ ls *.dat.old | sed 'p;s/.dat.old/_N.dat/' | xargs -n2 mv
1 Like
for file in *.dat.old
do
  mv "$file" "${file%.dat.old}_N.dat"
done
1 Like

great thanks much