卸下文件名单词列表 [英] Remove a list of words from filename

查看:186
本文介绍了卸下文件名单词列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图去除所有我的文件特定单词的列表与某个目录,并与没有取代他们。

I am trying to remove a list of specific words from all my files with a certain directory and replace them with nothing.

所以:

这真棒内容的720p BLAH FOO BANG OOO - 30.9.2013.mp4

This Awesome Content 720p BLAH FOO BANG OOO - 30.9.2013.mp4

变成了:

这真棒内容 - 30.9.2013.mp4

This Awesome Content - 30.9.2013.mp4

现在以下为一个发现的伟大工程,更换一个字。

Now the following works great for a single find and replace one word.

find path/to/folder/ -maxdepth 3 -name '*.*' -execdir bash -c 'mv -i "$1" "${1//foo/}"' bash {} \;

我也尝试过多个发现,但这个好像做了很长的路,我似乎遇到问题这样。

I have also tried just multiple finds but this seems like a very long way of doing it and i seem to run into issues this way.

问题的夫妇,我有:


  • 希望它是区分大小写

  • 极品$ {1 //富/}来指代一个列表

  • 如果大于1
  • 删除空格

试图运行此作为一个cronjob bash脚本。

Trying to run this as a bash script on a cronjob.

除非有办法这真棒内容之间移除一切美好 - 30.9.2013.mp4

Unless there is a better to way to remove everything between "This Awesome Content" - "30.9.2013.mp4".

大部分AP preciated。

Much appreciated.

推荐答案

您可以访问的文件名作为使用'回声'命令的变量。一旦做到这一点,最有力的方法,使您所需的更改是使用sed的'。您可以串起来用'-e'标志的sed命令。至于在bash循环的一部分,此行给你一个开始。您也可以使用这样的线路上,发现语句的一部分。

You can access a file's name as a variable using the 'echo' command. Once that is done, the most powerful way to make your desired changes is to use 'sed'. You can string together sed commands with the '-e' flag. As part of a for loop in bash, this line gives you a start. You can also use a line like this as part of your 'find' statement.

echo $fyle | sed -e 's/FOO//gI' -e 's/BANG//gI'

一旦你有你想要的文件名,然后你可以移动它们回到原来的名称。让我知道如果你需要更具体的说明。

Once you have your desired file names, you can then move them back to the original name. Let me know if you need more specific instructions.

更新:的下面是一个更完整的解决方案。你必须调整脚本到您自己的文件名等。

UPDATE: Here is a more complete solution. You'll have to tune the script to your own file names, etc.

for fyle in $(find . -name "*.*")
do 
   mv -i $fyle `echo $fyle | sed -e 's/FOO//gI' -e 's/BANG//gI' `
done

最后,与一个空白字符替换多个空格字符,你可以添加其他的sed命令。以下是一个命令:

Finally, to replace more than one whitespace character with one whitespace character, you can add another sed command. Here is a working command:

echo "file    input.txt" | sed 's/  */ /g'

这篇关于卸下文件名单词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆