I would make some slight modifications to your script. First don't use ls
in your for
loop, use *.csv
because the glob will handle non-printable characters and spaces in file names. Instead of using sed's inplace redirect to $file.bak
. If strings
is available on your system then replace sed
with strings
. And always remember to quote variables.
for file in *.csv do sed 's/^M//' "$file" > "$.bak" #strings "$file" > "$.bak" iconv -f -iso-8859-1 -t utf8 "$.bak" > "$file" rm "$.bak" done