How does linux filter control characters

12-15-2022

This article mainly introduces the relevant knowledge about how Linux filters control characters. The content is detailed and easy to understand, the operation is simple and fast, and has certain reference value. I believe that everyone will gain something after reading this article on how Linux filters control characters. We together look.


The command that can filter control characters in Linux is col. The col command is a document editing command under linux. Its full English name is colation, which translates to filtering. The col command mainly has a function, which can effectively filter out control characters in many description files. The syntax col [-bfx][- l]. The col command is equivalent to a standard input text filter, which reads text content from the label input device and displays the content to the label output device.

The command that can filter control characters in Linux is col.

Linux col command

The col command is a document editing command under linux. Its full English name is colation, which translates to filtering. The col command mainly includes A feature that effectively filters out control characters in many specification files.

Description: The col command is equivalent to a standard input text filter, which will read the text content from the label input device and display the content to the label output device.

In many UNIX documentation, there are RLF control characters. When we use the shell special characters ">" and ">>" to output the content of the description file into a plain text file, the control characters will become garbled characters, and the col command can effectively filter out these control characters.

Syntax


col [-bfx][-l]


Parameters:

  • -b Filter out all control characters, including RLF and HRLF.

  • -f Filter out RLF characters, but allow HRLF characters to be rendered.

  • -x represent tab characters as multiple space characters.

  • -lThe preset memory buffer has 128 columns, and you can specify the size of the buffer yourself.

col command instance

(1) Replace Tab with spaces, generally 1 Tab into 4 spaces .


echo -e 123 456 | col -x


(2) Replace spaces with Tabs, usually 4 Spaces are converted to 1 Tab.


echo -e 123 456 | col -h


(3) Delete the control character in the help document. Take the manual of the col command as an example.


man col | col -b > man_col.txt


(4) Take the man command help document as an example below, Explain the use of the col command.

Save the help file of the man command as man_help, use the -b parameter to filter all control characters. Use the following command in the terminal:


man man | col-b > man_help


Note: where "|" is used It is used to establish a pipeline to convert the output result of the man command into the input data of the col command.


Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us