Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
432 views
in Technique[技术] by (71.8m points)

bash: find -exec and filenames

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 ; 

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.

For instance, I have

2002/filename.html

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

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

I'm using cygwin.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The redirection happens outside of find. Invoke a subshell.

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...