清理目录中的文件名

发布于 2024-10-01 04:50:57 字数 692 浏览 0 评论 0原文

我想运行一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倒数 2024-10-08 04:50:57

您可能希望将所有句点转换为空格,然后通过管道输入设置扩展名的命令。

示例(忽略您指出的其他特殊情况):

tr '.' ' ' | sed 's/ \([^ ]*\)$/.\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):

tr '.' ' ' | sed 's/ \([^ ]*\)$/.\1/'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文