从文件名中删除匹配的正则表达式

从文件名中删除匹配的正则表达式

我是广播电台的所有者,我的 Cent OS PC 上有超过 5000 首曲目。他们的名字是这样的

01. Craig David - Love Yourself (Live from BBC Radio's Live Lounge).mp3
01. The Maccabees - Hello (Live from BBC Radio's Live Lounge).mp3
02. Lukas Graham - 7 Years (Live from BBC Radio's Live Lounge).mp3
02. The Weeknd - Can't Feel My Face (Live from BBC Radio's Live Lounge).mp3
03. Blonde - Work - Pillowtalk - Children (Live from BBC Radio's Live Lounge).mp3
03. Olly Murs - Can't Stop the Feeling - Rock Your Body (Live from BBC Radio's Live Lounge).mp3
04. Coldplay - Adventure of a Lifetime (Live from BBC Radio's Live Lounge).mp3
04. One Direction - Four Five Seconds (Live from BBC Radio's Live Lounge).mp3
05. Jonas Blue - Hotter Than Hell (Live from BBC Radio's Live Lounge).mp3
05. Nick Jonas - Lush Life (Live from BBC Radio's Live Lounge).mp3
06. Fifth Harmony - Ex's & Oh's (Live from BBC Radio's Live Lounge).mp3
06. Jack Garratt - Worry (Live from BBC Radio's Live Lounge).mp3
07. Lower Than Atlantis - On My Mind (Live from BBC Radio's Live Lounge).mp3
07. Usher - Crash (Live from BBC Radio's Live Lounge).mp3
08. Gorgon City - One Dance (Live from BBC Radio's Live Lounge).mp3
08. Grace - You Don't Own Me (Live from BBC Radio's Live Lounge).mp3
09. Dua Lipa - The Hills (Live from BBC Radio's Live Lounge).mp3
09. Mike Posner - In Ibiza (Live from BBC Radio's Live Lounge).mp3
10. DNCE - Hands to Myself (Live from BBC Radio's Live Lounge).mp3
10. Shawn Mendes - Stitches (Live from BBC Radio's Live Lounge).mp3
11. James Bay - Hymn for the Weekend (Live from BBC Radio's Live Lounge).mp3
11. Karen Harding - PILLOWTALK (Live from BBC Radio's Live Lounge).mp3
12. The 1975 - Sorry (Live from BBC Radio's Live Lounge).mp3
12. Tom Odell - The Sound (Live from BBC Radio's Live Lounge).mp3
13. Alessia Cara - Hotline Bling (Live from BBC Radio's Live Lounge).mp3
13. Birdy - Fast Car (Live from BBC Radio's Live Lounge).mp3
14. Jamie Lawson - Wasn't Expecting That (Live from BBC Radio's Live Lounge).mp3
14. M.O - How Will I Know - Perfect Strangers (Live from BBC Radio's Live Lounge).mp3
15. CHVRCHES - This Is What You Came For (Live from BBC Radio's Live Lounge).mp3
15. Kygo - Wildest Dreams (Live from BBC Radio's Live Lounge).mp3
16. Bastille - 7 Days - Final Song (Live from BBC Radio's Live Lounge).mp3
16. Fleur East - Sax (Live from BBC Radio's Live Lounge).mp3
17. Biffy Clyro - (Live from BBC Radio's Live Lounge).mp3
17. Blossoms - In2 (Live from BBC Radio's Live Lounge).mp3
18. Charlie Puth - We Don't Talk Anymore (Live from BBC Radio's Live Lounge).mp3
18. Izzy Bizu - White Tiger (Live from BBC Radio's Live Lounge).mp3
19. Clean Bandit - Work from Home (Live from BBC Radio's Live Lounge).mp3
19. Laura Mvula - New Person, Same Old Mistakes (Live from BBC Radio's Live Lounge).mp3

我想01.从文件名中删除。我发现了几个与我相同的问题,但在我的 centos 7 安装中没有答案对我有用。

/^\d\d. /g

这是我想出的正则表达式,当我在这里测试它时它匹配

http://regexr.com/

但我完全不知道如何用 sed 来实现它,或者用 rename 来查找。真是让我大吃一惊...

答案1

zsh

autoload zmv # best in ~/.zshrc
zmv -n '<->. (*)' '$1'

高兴的时候就删掉-n

<x-y>x匹配和之间的十进制数y<->是任意数字。

答案2

sed和 的解决方案sh

for FILE in *.mp3
do mv "$FILE" "$(echo $FILE | sed -r 's/^[[:digit:]]{2}\. //g')"
done

答案3

要删除文件名中的前四个字符:

for fpath in path/to/songs/*.mp3; do
  fname="${fpath##*/}"
  newname="${fname:4}"
  echo mv "${fpath}" "${fpath%/*}"/"$newname"
done

echo一旦您确定它正在做正确的事情,请将其删除。

相关内容