如何删除不在文件2中的文件1



我有2个文件;File1和file2。File1有许多行/行和列。File2只有一列,有几行/几行。file2中的所有字符串都可以在file1中找到。我想创建一个新文件(file3),

例如,

File1:

Sally ate 083 popcorn
Rick has 241 cars
John won 505 dollars
Bruce knows 121 people

File2:

083
121

所需file3:

Sally ate 083 popcorn
Bruce knows 121 people

就用grep -f:

$ cat file1
Sally ate 083 popcorn
Rick has 241 cars
John won 505 dollars
Bruce knows 121 people
$ cat file2
083
121
$ grep -f file2 file1
Sally ate 083 popcorn
Bruce knows 121 people

将输出保存在file3中:

grep -f file2 file1 > file3

相关内容

  • 没有找到相关文章

最新更新