VIM - Bat to convert character encodings

maeq

I have a .csv file downloaded from Google Drive in a codification that doesnt recognize accented characters (spanish characters).

With the VIM editor for Windows I'm able to solve this problem by opening the file (vim spanish.csv) and then inside the file type

 :write ++enc=utf-16 spanish-2.csv

Now I need to create a .bat or .ps1 to automatically do this for me. How can I do this?

P.D.: I've tried using iconv and I can't convert the file that I download from Google Drive since I don't know in with codification it is. I tried:

iconv -f ANSI:X3.4-1968 -t UTF-8 spanish.csv > spanish-2.csv
iconv -f ANSI:X3.4-1986 -t UTF-8 spanish.csv > spanish-2.csv
iconv -f ASCII -t UTF-8 spanish.csv > spanish-2.csv

And many other encodings but it says that the file can't be converted.

Ingo Karkat

find out the encoding

When you've opened the spanish.csv source file within Vim,

:setlocal fileencoding?

should tell you the detected encoding. There are also third-party tools like enca that can do this detection. You then only potentially need to translate the encoding name into the format expected by iconv.

convert with Vim

You can also directly use Vim for the conversion; Ex commands can be specified on the command-line via -c {cmd}:

vim -c "write ++enc=utf-16 spanish-2.csv" -c "quit" spanish.csv

With the use of :argdo, and a file name of %:r-2.%:e, you can even pass multiple source files to a single Vim instance for conversion.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Vim regex - hex character in replacement?

분류에서Dev

convert character set (German)

분류에서Dev

convert character linestring to geometry in sf

분류에서Dev

how to convert a character array to decibel

분류에서Dev

Trying to Convert String to Character Pointer?

분류에서Dev

How to convert decimal value to character in c language

분류에서Dev

How to convert unicode to its original character in Python

분류에서Dev

Swift Convert Hex String or Character to Integer

분류에서Dev

VIM-문자 인코딩을 변환하는 Bat

분류에서Dev

How to convert a json string into an individual character array in bash?

분류에서Dev

Convert an array of character to string from index i to j in c++

분류에서Dev

Convert keycode to character using javascript,like keyCode 27 to esc

분류에서Dev

Delete weird ANSI character and convert accented ones using Python

분류에서Dev

How do I convert a TTF into individual PNG character images?

분류에서Dev

vim 스크립트를 실행하면 배치 파일이 종료됩니까? (Windows .BAT / .CMD)

분류에서Dev

In bash, how can I convert a Unicode Codepoint [0-9A-F] into a printable character?

분류에서Dev

Convert escape characters in strings (like "\\n" - two characters) into ASCII character (newline)

분류에서Dev

FreeDOS AUTOEXEC.BAT

분류에서Dev

FreeDOS AUTOEXEC.BAT

분류에서Dev

uwsgi 오류-ModuleNotFoundError : 'encodings'라는 모듈이 없습니까?

분류에서Dev

Schtasks CMD .bat 문제

분류에서Dev

How to stop a bat process on Windows?

분류에서Dev

Launching a .reg within a .bat file

분류에서Dev

WMIC command not working in .bat file

분류에서Dev

.bat 파일 실행

분류에서Dev

Unknown Character

분류에서Dev

What is this character: '*'?

분류에서Dev

character and array

분류에서Dev

Postgres upgrade from 10.4 to 11.5 encodings for database "postgres" do not match: old "SQL_ASCII", new "UTF8"

Related 관련 기사

  1. 1

    Vim regex - hex character in replacement?

  2. 2

    convert character set (German)

  3. 3

    convert character linestring to geometry in sf

  4. 4

    how to convert a character array to decibel

  5. 5

    Trying to Convert String to Character Pointer?

  6. 6

    How to convert decimal value to character in c language

  7. 7

    How to convert unicode to its original character in Python

  8. 8

    Swift Convert Hex String or Character to Integer

  9. 9

    VIM-문자 인코딩을 변환하는 Bat

  10. 10

    How to convert a json string into an individual character array in bash?

  11. 11

    Convert an array of character to string from index i to j in c++

  12. 12

    Convert keycode to character using javascript,like keyCode 27 to esc

  13. 13

    Delete weird ANSI character and convert accented ones using Python

  14. 14

    How do I convert a TTF into individual PNG character images?

  15. 15

    vim 스크립트를 실행하면 배치 파일이 종료됩니까? (Windows .BAT / .CMD)

  16. 16

    In bash, how can I convert a Unicode Codepoint [0-9A-F] into a printable character?

  17. 17

    Convert escape characters in strings (like "\\n" - two characters) into ASCII character (newline)

  18. 18

    FreeDOS AUTOEXEC.BAT

  19. 19

    FreeDOS AUTOEXEC.BAT

  20. 20

    uwsgi 오류-ModuleNotFoundError : 'encodings'라는 모듈이 없습니까?

  21. 21

    Schtasks CMD .bat 문제

  22. 22

    How to stop a bat process on Windows?

  23. 23

    Launching a .reg within a .bat file

  24. 24

    WMIC command not working in .bat file

  25. 25

    .bat 파일 실행

  26. 26

    Unknown Character

  27. 27

    What is this character: '*'?

  28. 28

    character and array

  29. 29

    Postgres upgrade from 10.4 to 11.5 encodings for database "postgres" do not match: old "SQL_ASCII", new "UTF8"

뜨겁다태그

보관