3

In Ed I can test for whitespace with this regex: g/ *$/p. I don't suppose there is a way of showing whitespace, perhaps by passing the contents of the buffer to another shell command?

1 Answer 1

5

You may use the l ("ell") command in ed (and in sed, vi, and ex too, BTW) to display lines in a visually unambiguous form. The command is used analogous to the p and n commands but shows end-of-line as $, tabs as \t, and carriage returns as \r (there are some other special characters that are similarly marked up too, see the POSIX specification). Spaces are shown as-is:

a
this line ends with two spaces and a tab    
.
l
this line ends with two spaces and a tab  \t$

If you want to list all lines that have spaces at the end of them and display these with their line number and with l:

g/ $/ ln

You may also pipe the contents of the buffer, or any range of lines, to your system's cat command, if it knows how to display lines in a similar way to the l command in ed, e.g. w ! cat -A with BusyBox's cat, or w ! cat -v with OpenBSD's cat (which will do even more markup of the text).

If you want to see spaces, as in "replace every space with some visually catching character, like *", you can do that in ed with the s command on the current line:

s/ /*/gp

... or on all lines that contain a space:

g/ / s//*/gn

(I'm using n in place of p there to make it easier to locate the lines in the document.)

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.