The situation:
I have a bunch of text files (.csv, to be precise), around 20000 that differ in character encoding: file -i *.csv
gives me charset=us-ascii
for most, but some are utf-16le
.
The goal:
I want them all to be encoded the same way, us-ascii here. I think of a one-liner that checks for each file in the directory the encoding, and if it is utf-16le
, it converts it to us-ascii
.
I only started to learn bash programming a few day ago, so this one still escapes me. Is it possible, something like running file -i on each file (did that), capturing the return value, check what encoding is given and if it is not us-ascii, convert it?
Thanks for helping me understand how to do that!