Skip to Content
sed & awk, 2nd Edition
book

sed & awk, 2nd Edition

by Dale Dougherty, Arnold Robbins
March 1997
Intermediate to advanced
432 pages
11h 31m
English
O'Reilly Media, Inc.
Content preview from sed & awk, 2nd Edition

List

The list command (l) displays the contents of the pattern space, showing non-printing characters as two-digit ASCII codes. It is similar in function to the list (:l) command in vi. You can use this command to detect “invisible” characters in the input.[6]

$ cat test/spchar
Here is a string of special characters: ^A  ^B
^M ^G
$ sed -n -e "l" test/spchar
Here is a string of special characters: \01 \02 
\15 \07
$ # test with GNU sed too
$ gsed -n -e "l" test/spchar
Here is a string of special characters: \01  \02
\r \a

Because the list command causes immediate output, we suppress the default output or we would get duplicate copies of the lines.

You cannot match a character by ASCII value (nor can you match octal values) in sed.[7] Instead, you have to find a key combination in vi to produce it. Use CTRL-V to quote the character. For instance, you can match an ESC character (^[). Look at the following script:

# list line and replace ^[ with "Escape"
l
s/^[/Escape/

Here’s a one-line test file:

The Great ^[ is a movie starring Steve McQueen.

Running the script produces the following output:

The Great \33 is a movie starring Steve McQueen.
The Great Escape is a movie starring Steve McQueen.

GNU sed produces this:

The Great \1b is a movie starring Steve McQueen.
The Great Escape is a movie starring Steve McQueen.

The ^[ character was made in vi by entering CTRL-V, then pressing the ESC key.

Stripping Out Non-Printable Characters from nroff Files

The UNIX formatter nroff produces output for ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

The AWK Programming Language, 2nd Edition

The AWK Programming Language, 2nd Edition

Alfred V. Aho, Brian W. Kernighan, Peter J. Weinberger

Publisher Resources

ISBN: 1565922255Supplemental ContentErrata Page