I'm trying to find all text files which have the encoding iso-8859-1 and convert these to UTF-8. My attempt so far is:
find . -name '*.txt' | xargs grep 'iso-8859-1' | cut -d ':' -f1 |
xargs iconv -f ISO-8859-1 -t UTF-8 {} > {}.converted
The (obvious) problem is that the last variable substitution won't work, since {}
occurs after the redirection, and doesn't belong to xargs
. As is I only get one file called {}.converted
, not a.txt.converted
, b.txt.converted
etc. How can I make this work?
Note: I'm doing this on Cygwin, where iconv doesn't seem to support -o
.