删除基于另一个文件的行

时间:2013-12-02 20:27:00

标签: unix sed awk grep

我有一个类似于在这里被问到的问题的unix问题

Delete lines based on pattern on another file

我有file1.txt,其内容为

part1
part2
part3
part4

我有另一个file2.txt,其内容是(它有2000行)

part1
part2
part3
...
part2000

我想从file2.txt中删除与file1.txt内容匹配的所有行。我按照上面的帖子的建议尝试了解决方案,但是我的SUN Unix服务器上没有这些标签。

% grep -Fvf file1.txt file2.txt > output.txt
grep: illegal option -- F
grep: illegal option -- f
Usage: grep -hblcnsviw pattern file . . .

2 个答案:

答案 0 :(得分:2)

在较旧的Solaris服务器上,尽可能使用/usr/xpg4/bin中的工具。

$ /usr/bin/grep
Usage: grep -hblcnsviw pattern file . . .
$ /usr/xpg4/bin/grep 
Usage:  grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [file ...]
grep [-E|-F] [-c|-l|-q] [-bhinsvwx] -e pattern... [-f pattern_file]...[file...]
grep [-E|-F] [-c|-l|-q] [-bhinsvwx] [-e pattern]... -f pattern_file [file...]

答案 1 :(得分:2)

我希望这有效

grep -v "`cat file1.txt`" file2.txt > tmp.in
相关问题