72

Possible Duplicate:
How can I convert multiple files to UTF-8 encoding using *nix command line tools?

Okay, now that I can detect the encoding, I know that my encoding is using charset=iso-8859-1 instead of utf. How can I convert this?

I say Reinstate Monica
  • 25,487
  • 19
  • 95
  • 131
Casebash
  • 7,337
  • 19
  • 68
  • 86

1 Answers1

122

Use iconv:

iconv -f iso-8859-1 -t utf-8 < file > file.new
Donald Duck
  • 2,473
  • 10
  • 29
  • 45
u1686_grawity
  • 426,297
  • 64
  • 894
  • 966
  • Ok, that might make sense indeed (though such straightforward answers are found in the other questions too). No need for the `<` by the way. – Arjan Jun 13 '10 at 12:44
  • 7
    @Arjan Note that Google points to this answer first.. – tomdemuyt Jun 18 '11 at 19:18
  • 2
    I did this.. now that file was completly emptied....... and I don't have any backup of it.. great.......... – OZZIE Nov 03 '18 at 14:33
  • 1
    @OZZIE then I am afraid you did it wrong – Matt Sephton Feb 11 '19 at 01:06
  • To clarify: should that be `` (no spaces) as in "substitute your filename here", or; are you redirecting the output with `>` and the preceding `<` is an error? There is a suggested edit (as well as the first comment) which suggests removing the `<`. I guess this is due to the spaces around `file` inside the `<...>` making it look confusing and as if the `<` is a typo. What increases the confusion is that the second `file.new` does not have `<...>`. You might want to fix that. I'd suggest that `iconv -f iso-8859-1 -t utf-8 .new` is better... at least it's consistant – Greenonline Jul 01 '22 at 06:46
  • 2
    @Greenonline: Both `<` and `>` are intentional – they redirect input from `file` and output into `file.new`. The input redirection is optional since iconv could read its input directly, but I wanted it to be present for consistency. – u1686_grawity Jul 01 '22 at 07:50
  • You should add your comment to the answer, as it may be interesting to the uninitiated about the input redirection being optional - maybe show both forms of the command line, up to you. Nevertheless, the command line looks better now... :-) – Greenonline Jul 01 '22 at 09:11