Search code examples
bashshellseddiacriticsiconv

How to remove accents from a file using a cron job?


I have a .sh file that convert accents into unaccent chars using iconv, so I have this file:

$FUT2
#Containing
<span>Panamá</span>

Running the .sh manually from the command line:

#!/bin/sh
iconv -f utf8 -t ascii//TRANSLIT "$FUT2" > "$FUT"

I get in the file:

<span>Panama</span>

Thats nice, but when I run it from the cron, using webmin and setting up a scheduled cron job, then i get:

<span>Panam?</span>

and, if I use sed

Running the .sh manually from the command line:

#!/bin/sh
sed -e 's/[á]/a/g;s/[é]/e/g;s/[í]/i/g;s/[ó]/o/g;s/[ú]/u/g'  "$FUT2" > "$FUT"

<span>Panama</span>

Running from webmin

<span>Panamaa</span>

The .sh its UTF-8 without BOM

So any idea how to fix it or any other way how to replace the accents? Thanks


Solution

  • Did you try to set the var LANG=en_US.UTF-8 in the crontab command?

    0 5 * * 1 LANG=en_US.UTF-8 iconv -f utf8 -t ascii//TRANSLIT "file1" > "file2"