linux col 过滤控制字符

参考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帮助输出文件打开是乱码的问题。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您可以通过为 QTableWidget 添加一个右键菜单来实现过滤功能。以下是实现这种功能的基本步骤: 1. 为 QTableWidget 添加一个右键菜单。 2. 在菜单中添加一个 QAction,用于触发过滤操作。 3. 当用户单击 QAction 时,获取 QTableWidget 中的数据并进行过滤。 4. 更新 QTableWidget 中的数据,以显示过滤后的结果。 以下是一个示例代码,演示如何创建一个带有菜单过滤功能的 QTableWidget: ```cpp // 创建 QTableWidget QTableWidget* tableWidget = new QTableWidget(this); tableWidget->setRowCount(5); tableWidget->setColumnCount(3); // 添加数据 for (int row = 0; row < 5; ++row) { for (int col = 0; col < 3; ++col) { QTableWidgetItem* item = new QTableWidgetItem(QString("item %1,%2").arg(row).arg(col)); tableWidget->setItem(row, col, item); } } // 添加右键菜单 tableWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(tableWidget, &QTableWidget::customContextMenuRequested, this, [=](const QPoint& pos) { QMenu menu; QAction* filterAction = menu.addAction("Filter"); QAction* selectedAction = menu.exec(tableWidget->viewport()->mapToGlobal(pos)); if (selectedAction == filterAction) { // 获取选中行 QList<QTableWidgetItem*> selectedItems = tableWidget->selectedItems(); QList<int> selectedRows; for (auto item : selectedItems) { if (!selectedRows.contains(item->row())) { selectedRows.append(item->row()); } } // 过滤数据 for (int row = 0; row < tableWidget->rowCount(); ++row) { if (!selectedRows.contains(row)) { tableWidget->hideRow(row); } } } }); ``` 此代码将创建一个包含 5 行和 3 列的 QTableWidget,并在单元格中添加一些数据。它还为 QTableWidget 添加了一个右键菜单,其中包含一个名为“Filter”的 QAction。当用户单击“Filter”菜单项时,将获取选中行并过滤数据,以仅显示选定行。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值