0

Pulling my hair out - somebody save me from an early Q-ball.

I have a folder with loads of powerpoint files and I want to change a substring in each title. All of them are of the form "lecture 2 2014.pptx" and I want to change "2014" to "2016".

Insider the directory I try commands like:

find . -name "*2014*" | xargs -0 sed -i 's/2014/2016/g'

to no avail. Any advice?

Edit my goal is to change the file name. "Lecture 2 2014.pptx" to "Lecture 2 2016.pptx"

invictus
  • 1,821
  • 3
  • 25
  • 30

2 Answers2

0

rename s/2014/2016/ *2014.pptx

If your list is too long to expand by shell try:

find -name \*2014.pptx -exec rename s/2014/2016/ {} \;

nsilent22
  • 2,763
  • 10
  • 14
0

rename was already mentioned. Be aware that there are two version floating around: one with the syntax

rename [options] expression replacement file...

and one with the syntax

rename s/old/new/ file...

As an alternative: a simple Bash loop with a regex extracting the "2014" from each file name, replacing it with "2016"

re='(.*)2014(.*)'

for fname in *2014*; do
    [[ $fname =~ $re ]]
    mv "$fname" "${BASH_REMATCH[1]}2016${BASH_REMATCH[2]}"
done
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116