5

When I try to use Context.write(k,v) in MapReduce(using Java) to write data to a file ,I find the following contents in file(opened with vi, have :set list):

^@R^@u^@n^@^I1$
^@a^@c^@c^@e^@s^@s^@^I1$
^@d^@e^@f^@a^@u^@l^@t^@ 2$
^@o^@u^@t^@^I2$
^@p^@r^@o^@j^@e^@c^@t^@^I1$
^@t^@a^@s^@k^@^I1$
^@w^@i^@n^@d^@o^@w^@s^@^I1$
^@y^@o^@u^@r^@^I1$

What's the meaning of ^@ ^I and $? Does ^I mean \t? I know that $ means the end of the line, but does it mean the enter key, just like \n? If so, what's the difference between '$' and '^M' in vi?

Searene
  • 903
  • 2
  • 11
  • 14

3 Answers3

5

$ is the end of line as displayed by :set list with the default value of the listchar option. ^I is the tab character.

^@ is the null character.

For some weird reason every meaningful character in your file is prepended with a null character except digits and (probably) spaces.

This is not a Vi(m) problem: check the documentation of that method to see if there's a way to output your data without those nulls.

romainl
  • 23,415
1

The file that you opened is UTF-16 or UCS-2 encoded, which is the standard in Java. vi (as in real vi, not vim symlinked to vi) can only handle ASCII (or ISO-8859-1?) text. Use vim, or convert the file to ASCII (e.g., iconv -f utf-16 -t ascii <input> <output>).

pilona
  • 1,783
0

If that's Vim behind your vi command, you can reload the file with

:edit ++enc=ucs-2

or directly specify the encoding

$ vim ++enc=ucs-2 filename

or, if you need to open these files frequently, prepend ucs-2 to the 'fileencodings' option, e.g. in your ~/.vimrc.

Ingo Karkat
  • 23,523