8

I am trying to convert from unknown-8bit to us-ascii by using iconv. I have $ iconv -f unknown-8bit -t us-ascii file.txt > file1.txt

It shows an error message.

iconv: conversion from `unknown-8bit' is not supported
Try `iconv --help' or `iconv --usage' for more information.

Is there an alternative to conduct the conversion? Thank you!!

yearntolearn
  • 1,064
  • 2
  • 17
  • 36

2 Answers2

11

You could use cat -v, e.g.,

cat -v file.txt > file1.txt

On most platforms, that will give an ASCII file.

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
  • Accentuated characters (é, è, ê, ...) are lost in the new file. Is there a way keep them? – Psddp Feb 04 '19 at 21:32
  • Those aren't ASCII. In a quick-test, I'm seeing those become `M-i, M-h, M-j, ...`, which is expected. – Thomas Dickey Feb 04 '19 at 21:59
  • @ThomasDickey why is this encoding expected and do you have a list of what they represent? – Guilherme Sampaio May 13 '20 at 01:38
  • The accented characters are coded in the range 160-255, while US-ASCII is only defined for (printable) 32-126, so any program that handles the conversion will use some workaround to represent the out-of-range codes. The "M" denotes meta, which is used for instance in [terminfo](https://invisible-island.net/ncurses/man/terminfo.5.html#h3-Miscellaneous) and curses. iconv came "later", so it didn't originate the "M". – Thomas Dickey May 13 '20 at 08:03
1

with accents, you can set it in vim as mentioned in this post: Set encoding and fileencoding to utf-8 in Vim

In my case, I have issue on '…', '−' and '-', I open the file under vim, correct issues and run in vim

:set fileencoding=utf-8

then save it and my file is utf-8 encoded!

bcag2
  • 1,988
  • 1
  • 17
  • 31