0

when I open file by vi

as

vi file

Current partition replica assignment
@
@
@
@
@
{"version":1,"partitions":[{"topic")]
@
@
@
@
@
Proposed partition reassignment configuration

but I try to delete this empty line

as

sed -i 's/^ *//; s/ *$//; /^$/d; /^\s*$/d' file

or

sed -i '/^$/d'  file

or

sed -i '/^$/d' file

still file is with the empty lines

how to remove the empty/blank lines ?

  • 1
    Perhaps somewhat related: Characters visible in vi, but not in cat. – steeldriver Jan 24 at 14:32
  • 2
    It'd be best if you used hexdump -C input.txt or od -tx1c input.txt to figure out what those characters really are. – haukex Jan 24 at 14:55
  • Do you want to remove all lines that content a single @? – Emilio Galarraga Jan 24 at 14:55
  • Do you want to remove all lines that content a single @ - yes ( but they only appears from vi ) – yael Jan 24 at 15:02
  • 1
    Everyone seems to be taking the question at face value that these are blank lines, assuming that these are NULs (despite the fact that vi does not display NUL like this), and forgetting the more usual reason that vi displays @ characters in column 1. A big clue would be if the question were to mention that these lines were in a different colour to the other text. – JdeBP Jan 24 at 15:38
6

Those are not empty lines, but lines that are too long to fit on the screen, even after wrapping.

$ perl -e 'print "foo\n", "bar " x 4096' >/tmp/file
$ vim /tmp/file

foo
@
@
@
...

This is what the standard says:

In visual mode, if a line from the edit buffer (other than the current line) does not entirely fit into the lines at the bottom of the display that are available for its presentation, the editor may choose not to display any portion of the line. The lines of the display that do not contain text from the edit buffer for this reason shall each consist of a single '@' character.

Also look at the vim's documentation about the display option:

When neither "lastline" nor "truncate" is included, a last line that doesn't fit is replaced with "@" lines.

Do not confuse them with null bytes, which are usually shown as ^@ (notice the caret). Also, this behavior is not universal (it doesn't seem to be implemented in nvi).

  • Interestingly, one does not see this by default with nvi and NeoVIM. nvi simply does not do this, and NeoVIM has display=lastline set by default. – JdeBP Jan 24 at 16:43
0

It works well for me. Probably your file should have dos null values...

To view:

vim -b file

To convert to unix

dos2unix file
  • dos2unix , still stay the @ in the file when editing it by vi – yael Jan 24 at 14:28
  • can u share the result of vim -b file – msp9011 Jan 24 at 14:34
0

Those are null bytes, I believe. cat -A file would display them as ^@

tr can handle those:

tr -d '\0' < file > file.new
  • Here's a way to create a test file: printf 'foo\n\0\nbar\n\0\nbaz\n' > file – glenn jackman Jan 24 at 14:38
  • still the empty lines exists ( from vi I still see @ ) – yael Jan 24 at 14:40
  • You should do some research about why vi is displaying that character. You should also investigate the upstream process that is creating your data file with odd characters in it. – glenn jackman Jan 24 at 14:44
  • yes I will do ... – yael Jan 24 at 14:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.