我有两个来自具有多行($old
和$new
)的文件的字符串。如何删除$new
中显示的$old
的所有内容?
前:
old:
oranges
apples
oranges
new:
oranges
apples
oranges
pineapples
output:
pineapples
答案 0 :(得分:3)
使用grep
并处理替换:
grep -vxFf <(printf '%s' "$old") <(printf '%s' "$new")
-v
- 检索不匹配的行-x
- 匹配整行-F
- 匹配为字符串,而不是正则表达式-f
- 从文件中读取字符串,而不是命令行