开发者

Cleaning up filenames within a directory

开发者 https://www.devze.com 2023-01-23 19:25 出处:网络
I would like to run a bash script that recursively cleans up every filename in a directory. For example I have the filename:

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/\[sharethefile开发者_如何学运维s\.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!


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/'
0

精彩评论

暂无评论...
验证码 换一张
取 消