本文介绍了bash:查找 -exec 和文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从几百个文件中删除 HTML.

I want to strip the HTML out of few hundred files.

这是我开始使用的命令:

Here's the command I've started with:

find -name *.html -exec w3m {} > w3m {}.html.out ;

我遇到的问题是它创建了一个大的 .htm.out 文件(名为 {}.html.out)——我希望我使用的文件被命名为原始文件是 .out.

The problem I've run into is that it created one single large .htm.out file (named {}.html.out) -- I want the file I'm using to be named whatever it's original is .out.

例如,我有

2002/filename.html

我想通过w3m运行,得到2002/filename.html.out

I want to run it through w3m, and get 2002/filename.html.out

有什么建议吗?我对其他不使用 bash 的解决方案持开放态度

Any suggestions? I'm open to other solutions that don't use bash

我正在使用 cygwin.

I'm using cygwin.

推荐答案

重定向发生在 find 之外.调用子shell.

The redirection happens outside of find. Invoke a subshell.

find -name *.html -exec bash -c 'w3m "$1" > w3m-"$1".html.out' w3mout {} ;

这篇关于bash:查找 -exec 和文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-24 03:23