Pervy Sage Pervy Sage - 4 months ago 64
Javascript Question

How do I JS-Beautify recursively?

I have lots of html files in a directory and sub-directories. I can execute

js-beautify
command through the command line and want to apply it recursively to all those files.

I have tried
find . -name "*.html" -type f | js-beautify -r
and
js-beautify -r | find . -name "*.html" -type f
but it doesn't work. However, JS-beautify does work if I give something like
js-beautify -r myfile.html
or
js-beautify -r *.html
(in case of all the files in a directory but not in sub-directory)

Can anyone tell how should I be piping these two commands?

Answer

However, JS-beautify does work ... in case of all the files in a directory but not in sub-directory

You've mentioned that JS-beautify works if all the input files are in the same directory. Your command doesn't probably work because you pass all the results from find which might include input files from different directories.

As mentioned in the comment earlier, you could use -exec instead:

find . -type f -name "*.html" -exec js-beautify -r {} \;
Comments