I am trying to change the encoding of a text file to UTF-8.

I am new to Unix so any help would be great. I am not sure how to code it properly with recode function.

  • 4
    Are you aware there are two independent questions there? ISO-8859→UTF-8 and CR+LF→LF
    – Pablo A
    Nov 16, 2023 at 0:17
  • @PabloA The question isn't asking about CRLF -> LF conversion though.
    – marcelm
    Nov 16, 2023 at 8:26
  • Which national variant of ISO-8859? Do you want to insert a BOM? If all you've got is a 7-bit ASCII file and you don't want a BOM there's no practical difference. Nov 16, 2023 at 8:30
  • Also check that it really is ISO 8859-1 and not Windows code page 1252 en.wikipedia.org/wiki/Windows-1252
    – PM 2Ring
    Nov 16, 2023 at 9:35

1 Answer 1


Most immediate would probably be using iconv

The way suggested in the manual ( iconv -f ISO88592 -t UTF8 < input.txt > output.txt ) might not work with ISO-8859 as parameter since the subpart of the norm (-1… -9… -14…) is likely to be needed but… iconv should be able to automatically recognize the encoding of the source file. So… simply try :

iconv -t UTF-8 yourfilename

Additionally, and as wisely suggested by Marcus, if also willing to convert the dos-like line endings to *nix standards (CR-LF -> LF) you can use dos2unix. Note that depending on your distribution you might need to install some extra package. In case this causes problems, you can also use more standard tools for removing the CR :

Using tr : tr -d '\r' < yourfilename_withCRLF > yourfilename_LFonly

Using sed : sed -i 's/\r$//g' youfilename_withCRLF

  • 4
    … and to convert the line endings, dos2unix. Nov 15, 2023 at 23:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .