Unix- Using Grep to get unmatched lines

给你一囗甜甜゛ 提交于 2020-01-24 00:35:06

问题


I am new to unix. I want to grep the unmatched pattern from a file1 provided that the patterns are in the file2. The real files are having more than 1000 lines.

Example:

File1:
Hi(Everyone)
How(u)people(are)doing?
ThanksInadvance

File2:
Hi(Every
ThanksI

Required Result:

How(u)people(are)doing?

I want only the pattern to be used like ("Hi(Every") for the grep.It should return the unmatched line from file1.


回答1:


this line works for given example:

grep -Fvf file2 file1

The 3 options used above:

-F  makes grep do fixed-string match
-v  invert matching
-f  get patterns from file



回答2:


the Grep-Flag -v inverts the Grep-Command.

cat File1 |grep -v ("Hi(Every") 

should return all Lines from File1 where ("Hi(Every") doesnt contains.

best regards,

Jan



来源:https://stackoverflow.com/questions/38328065/unix-using-grep-to-get-unmatched-lines

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!