小编Gir*_*ish的帖子

bash 从两个文件中删除公共行

我有两个文件,(没有空行/空格/制表符)

/tmp/所有

aa  
bb  
cc  
hello  
SearchText.json  
xyz.txt  
Run Code Online (Sandbox Code Playgroud)

/tmp/必需

SearchText.json 
Run Code Online (Sandbox Code Playgroud)

我想要的最终输出是:(来自 /tmp/all 的所有不常见行)

aa  
bb  
cc  
hello  
xyz.txt 
Run Code Online (Sandbox Code Playgroud)

我尝试过以下命令:-

# comm -23 /tmp/required /tmp/all

SearchText.json
Run Code Online (Sandbox Code Playgroud)

# comm -23 /tmp/all /tmp/required

aa  
bb  
cc
hello  
SearchText.json  
xyz.txt  
Run Code Online (Sandbox Code Playgroud)

# comm -13 /tmp/all /tmp/required

SearchText.json  
Run Code Online (Sandbox Code Playgroud)

# comm -13 /tmp/required /tmp/all

aa  
bb  
cc  
hello  
SearchText.json  
xyz.txt  
Run Code Online (Sandbox Code Playgroud)

# grep -vf /tmp/all /tmp/required

# grep -vf /tmp/required /tmp/all

aa  
bb  
cc  
hello  
SearchText.json  
xyz.txt  
Run Code Online (Sandbox Code Playgroud)

# comm -23 <(sort /tmp/all) <(sort /tmp/required)

aa  
bb  
cc  
hello …
Run Code Online (Sandbox Code Playgroud)

diff text-processing comm

2
推荐指数
1
解决办法
2129
查看次数

标签 统计

comm ×1

diff ×1

text-processing ×1