我需要另一双眼睛来告诉我这个管道和 sed 有什么问题
我再次尝试重命名一些视频文件,但我的命令再次遇到问题。如果我能让另一双眼睛来看看这个并找出我没有看到的东西,我将不胜感激。
我有这样的文件;
'DARK Matter S01E03 Episode Three.mp4'
'DARK Matter S01E04 Episode Four.mp4'
等等......
我试图从名称中删除“第三集”,“第四集”
等,并且我编写了这个命令,但它并没有按预期工作。
for file in *Episode*;do echo "rename \"$file\" "\"$file" | sed 's/ Episode*./.')";done
该命令的结果是;
rename "DARK Matter S01E03 Episode Three.mp4" "DARK Matter S01E03 Episode Three.mp4 | sed 's/ Episode*./.')
rename "DARK Matter S01E04 Episode Four.mp4" "DARK Matter S01E04 Episode Four.mp4 | sed 's/ Episode*./.')
rename "DARK Matter S01E05 Episode Five.mp4" "DARK Matter S01E05 Episode Five.mp4 | sed 's/ Episode*./.')
它无法识别 sed 的管道,并且我的 sed 命令本身编写不正确(我知道,我对正则表达式很糟糕)。 如果您能提供任何帮助,我将不胜感激。
Again I am trying to rename some video files, and again I am having problems with my command. If I could get another set of eyes to look at this and figure out what i'm not seeing I would be grateful.
I have files like this;
'DARK Matter S01E03 Episode Three.mp4'
'DARK Matter S01E04 Episode Four.mp4'
etc...
I am trying to remove the " Episode Three", " Episode Four"
etc from the names and I wrote this command, but it's not quite working as expected.
for file in *Episode*;do echo "rename \"$file\" "\"$file" | sed 's/ Episode*./.')";done
The result of this command is;
rename "DARK Matter S01E03 Episode Three.mp4" "DARK Matter S01E03 Episode Three.mp4 | sed 's/ Episode*./.')
rename "DARK Matter S01E04 Episode Four.mp4" "DARK Matter S01E04 Episode Four.mp4 | sed 's/ Episode*./.')
rename "DARK Matter S01E05 Episode Five.mp4" "DARK Matter S01E05 Episode Five.mp4 | sed 's/ Episode*./.')
It's not recognizing the pipe to sed and my sed command itself is not written correctly (I know, i'm terrible with regular expressions).
I would appreciate any help you could give.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
regex
并从BASH_REMATCH[]
数组中提取匹配的片段:注意:
regex
被定义为拾取第一个句点后的任何内容(例如,.mp4
、.mkv
、some.other.suffix
)typeset -p
命令显示BASH_REMATCH[]
数组的内容替换为
mv
假设以下文件:代码结果如下:
Using a
regex
and pulling the matching pieces from theBASH_REMATCH[]
array:NOTES:
regex
is defined to pickup anything after the first period (eg,.mp4
,.mkv
,some.other.suffix
)typeset -p
command to display the contents of theBASH_REMATCH[]
arraycp
withmv
once the results have been verifiedAssuming the following files:
The code results in the following:
我终于自己弄清楚了;
重命名“暗物质 S01E03 第 3 集.mp4” “暗物质 S01E03.mp4”
重命名“暗物质 S01E04 第 4 集.mp4” “暗物质 S01E04.mp4”
重命名“暗物质 S01E05 第 5 集.mp4” “暗物质 S01E05.mp4” ”
I figured it out myself finally;
rename "DARK Matter S01E03 Episode Three.mp4" "DARK Matter S01E03.mp4"
rename "DARK Matter S01E04 Episode Four.mp4" "DARK Matter S01E04.mp4"
rename "DARK Matter S01E05 Episode Five.mp4" "DARK Matter S01E05.mp4"