所以我尝试使用 awk
获取通信输出的第一列。
我读到 Tab 被用作 comm 的分隔符,所以我做了:
awk -F"\t" '{print $1}' comm-result.txt
comm-result.txt 包含以下输出:
comm -3 file1 file2
但这似乎行不通。
此命令还使用空格字符作为分隔符,当我的文件包含多个空格时,我会得到奇怪的结果。
我怎样才能只从 comm
获取第一列?
最佳答案
"So I'm trying to get the first column of comm output"
“comm file1 file2
”输出的第一列包含 file1
独有的行。您可以通过使用 -2
(抑制 file2
独有的行)和 -3简单地调用
(隐藏出现在两个文件中的行)。 comm
来跳过后处理
comm -2 -3 file1 file2 # will show only lines unique to file1
但是,如果您别无选择,只能处理 comm
的预运行输出,则作为 Carl mentioned , cut
是一个选项:
cut -f1 comm-results.txt
但是,对于第 1 列为空的情况,这会导致空行。为了解决这个问题,也许 awk
可能更合适:
awk -F"\t" '{if ($1) print $1}' comm-results.txt
---- ----------------
| |
Use tab as delimiter |
+-- only print if not empty
关于linux - 如何获取通信输出的第一列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8299553/