0

I would like to do some processing with ex (vim in ex/silent mode). There is however a strange behaviour if a line is empty. An extra space character is added to that line - even in binary mode. Is it possible to eliminate that?

Check out:

$ printf "a\n1st\n\n3rd\n.\n%%p\n" | ex -b | hexdump -C
00000000  31 73 74 0a 20 0a 33 72  64 0a

Note the Ex rows in printf: a for appending text, three rows, . to close append mode, %p to print everything)

a
1st

3rd
.
%p

The expected result is

00000000  31 73 74 0a 0a 33 72 64  0a
FERcsI
  • 388
  • 1
  • 10
  • It looks like you have a space on that supposedly empty line. Doing the same manually doesn't give me that extra space, though. – romainl Jun 23 '22 at 11:40
  • @romainl, Actually, no. You can see in `printf` that there is no space between the two `\n`. And if I simply save the output, this space does not appear, only if I use `:print` or `:list`. So this might be an internal issue of representation. – FERcsI Jun 24 '22 at 14:28

1 Answers1

0

printf doesn't seem to be where that extra space comes:

$ printf 'a\n1st\n\n3rd\n.\n%%p\n' | hexdump -C
00000000  61 0a 31 73 74 0a 0a 33  72 64 0a 2e 0a 25 70 0a |a.1st..3rd...%p.|
00000010

ex doesn't seem to be involved either, at least used in a somewhat more "normal" way:

$ printf "a\n1st\n\n3rd\n.\nwzob\nq\n" | ex | hexdump -C zob
00000000  31 73 74 0a 0a 33 72 64  0a                       |1st..3rd.|
00000009

but you are not using ex that way. You are somehow making a kind of screen dump to stdout, which might explain the appearance of that space.

Without knowing what you are actually trying to do it is hard to provide a better solution. In any case, being a full screen document-oriented program, ex is generally not suited for use in a pipe so you might want to look for a different approach.

romainl
  • 186,200
  • 21
  • 280
  • 313
  • Thanks, actually my environment is rather complex and I would like to use internal commands to print parts of the text. I know that this is not an intended way how to use vim/ex. And yes, it seems that those spaces are added by `print` and `list` commands or they are there in the internal representation for some reason and they are not removed by these commands (only when creating real output). – FERcsI Jun 23 '22 at 16:24