Dad*_*dou 27 linux shell command-line comm
所以我试图使用的第一列通信输出awk.我读到Tab被用作comm的分隔符,所以我做了:
awk -F"\t" '{print $1}' comm-result.txt
Run Code Online (Sandbox Code Playgroud)
使用comm-result.txt包含输出:
comm -3 file1 file2
Run Code Online (Sandbox Code Playgroud)
但这似乎不起作用.
这个推荐还将空格字符作为分隔符,当我的文件包含多个空格时,我得到奇怪的结果.
我怎么才能从第一列获得comm?
Sha*_*hin 32
"所以我试图获得第一列通信输出"
" comm file1 file2"输出的第一列包含唯一的行file1.您可以通过简单地调用跳过后处理comm用-2(抑制特有的线file2)和-3(抑制出现在两个文件中的行).
comm -2 -3 file1 file2 # will show only lines unique to file1
Run Code Online (Sandbox Code Playgroud)
但是,如果您别无选择,只能comm按照Carl提到的那样处理预运行输出,那么cut将是一个选项:
cut -f1 comm-results.txt
Run Code Online (Sandbox Code Playgroud)
但是,对于第1列为空的情况,这会导致空行.要解决这个问题,或许awk可能更合适:
awk -F"\t" '{if ($1) print $1}' comm-results.txt
---- ----------------
| |
Use tab as delimiter |
+-- only print if not empty
Run Code Online (Sandbox Code Playgroud)