参考http://blog.51cto.com/jim123/1833502
使用过Unix系统的人肯定会知道man帮助的功能强大,是官方的帮助文档,我们平时可以通过它来查询不知道如何使用的命令或者查询linux的系统C函数,所以有的时候我们需要把man里的帮助信息导出来,但是我们用>>或>直接导出的文件打开会有乱码,在许多UNIX说明文件里,都有RLF控制字符。当我们运用shell特殊字符>或者>>导出的明文件的内容输出成纯文本文件时,控制字符会变成乱码,这时候我们就要用col命令过滤这些字符。
语 法:col [-bfx][-l<缓冲区列数>]
参 数:
-b 过滤掉所有的控制字符,包括RLF和HRLF。
-f 滤除RLF字符,但允许将HRLF字符呈现出来。
-x 以多个空格字符来表示跳格字符。
-l<缓冲区列数> 预设的内存缓冲区有128列,您可以自行指定缓冲区的大小。
使用man col输出的英文部分:
NAME
col - filter reverse line feeds from input
SYNOPSIS
col [-bfpx] [-l num]
DESCRIPTION
Col filters out reverse (and half reverse) line feeds so the output is in the correct order with only forward and half forward line feeds, and replaces white-space characters with tabs where possible. This can be useful in processing the
output of nroff(1) and tbl(1).
Col reads from standard input and writes to standard output.
The options are as follows:
-b Do not output any backspaces, printing only the last character written to each column position.
-f Forward half line feeds are permitted (‘‘fine’’ mode). Normally characters printed on a half line boundary are printed on the following line.
-p Force unknown control sequences to be passed through unchanged. Normally, col will filter out any control sequences from the input other than those recognized and interpreted by itself, which are listed below.
-x Output multiple spaces instead of tabs.
-lnum Buffer at least num lines in memory. By default, 128 lines are buffered.
例如要把gcc的命令说明输出到gcc.txt中并过滤掉所有的控制字符:
man gcc |col -b > gcc.txt
使用col命令过滤掉控制字符以解决man帮助输出文件打开是乱码的问题。