physiker
physiker

Reputation: 919

Bulk copy and rename files by replacing a pattern

I have a large number of files which has version-stamp on it, e.g ( Av1.dat, B1v1.dat,.., inZ63v1.dat). I'd like to make a copy AND rename them by just replacing v1-->v2 to get (Av2.dat, B1v2.dat, .., inZ63v2.dat). What is the easiest way? Thank you!

Upvotes: 0

Views: 95

Answers (1)

Andrea Carron
Andrea Carron

Reputation: 1021

I haven't tested it, but this should work:

for file in <list of files> ; do
  cp -- "${file}" "$(echo "${file}" | sed -e 's/v1\.dat/v2\.dat/')"
done

Upvotes: 1

Related Questions