美文网首页shell
Shell grep 取差集、交集、并集

Shell grep 取差集、交集、并集

作者: 南岩飞雪 | 来源:发表于2019-10-22 20:21 被阅读0次
  • 使用常见的 grep 命令实现
  • 可以用 man grep 查看grep使用说明
Matcher Selection
       -F, --fixed-strings, --fixed-regexp
              Interpret PATTERN as a list of fixed strings, separated by newlines, any of which is to be matched.  (-F is specified by POSIX, --fixed-regexp is an obsoleted alias, please do not use it in new scripts.)
Matching Control
       -f FILE, --file=FILE
              Obtain patterns from FILE, one per line.  The empty file contains zero patterns, and therefore matches nothing.  (-f is specified by POSIX.)
       -v, --invert-match
              Invert the sense of matching, to select non-matching lines.  (-v is specified by POSIX.)

a差b

grep -F -v -f b.file a.file
cat a.file | grep -F -v -f b.file 

a交b

grep -F -f a.file b.file
cat b.file | grep -F -f a.file 

a并b

cat a.file b.file | sort | uniq

相关文章

网友评论

    本文标题:Shell grep 取差集、交集、并集

    本文链接:https://www.haomeiwen.com/subject/erscvctx.html