清理目录中的文件名
我想运行一个 bash 脚本来递归地清理目录中的每个文件名。例如,我的文件名是:
The.Sarah.Jane.Adventures.S04E07.The.Empty.Planet.Part1.WS.PDTV.XviD-BiA.[sharethefiles.com].avi The.Sarah.Jane.Adventures.S04E08.The.Empty.Planet.Part2.WS.PDTV.XviD-BiA.[sharethefiles.com].avi
我想将文件转换为:
The Sarah Jane Adventures S04E07 The Empty Planet Part1 .avi
The Sarah Jane Adventures S04E07 The Empty Planet Part2.avi
所以我有这个 sed 脚本:
sed -e's/\[sharethefiles\.com\]//g; s/WS//g; s/PDTV//g; s/Xvid-BiA//g; s/XviD-BiA//g; s/\.\.//g; s/\./\ /g;'
但它有问题。这 。 (句点)在后缀(avi)之前被删除,我不太确定如何用如此动态的文件替换它。有时后缀前可能只有一个空格,有时则没有,因为脚本还删除了双句点。
关于解决该问题有什么想法吗?
感谢您的帮助!
I would like to run a bash script that recursively cleans up every filename in a directory. For example I have the filename:
The.Sarah.Jane.Adventures.S04E07.The.Empty.Planet.Part1.WS.PDTV.XviD-BiA.[sharethefiles.com].avi
The.Sarah.Jane.Adventures.S04E08.The.Empty.Planet.Part2.WS.PDTV.XviD-BiA.[sharethefiles.com].avi
I want to convert the file to:
The Sarah Jane Adventures S04E07 The Empty Planet Part1.avi
The Sarah Jane Adventures S04E07 The Empty Planet Part2.avi
So I have this sed script:
sed -e's/\[sharethefiles\.com\]//g; s/WS//g; s/PDTV//g; s/Xvid-BiA//g; s/XviD-BiA//g; s/\.\.//g; s/\./\ /g;'
but it comes with problems. The . (period) is removed before the suffix (avi) and I am not really sure how to replace it with files being so dynamic. Sometimes there maybe only one space before the suffix and sometimes there are none since the script also removes double periods.
Any ideas as to fixing the issue?
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能希望将所有句点转换为空格,然后通过管道输入设置扩展名的命令。
示例(忽略您指出的其他特殊情况):
You might want to convert all periods to spaces and then pipe into a command that sets the extension.
Example (ignoring the other special cases you indicated):