grep ,comm命令等,后续更新中
1.求b中查找a相同的id:交集
grep -w -F -f <(less ID.txt) gff >gff (这个我平时用得多)
grep -w -F -f a.txt b.txt
grep -w -F -f a.txt b.txt | sort | uniq (集合要求排序)
-w, --word-regexp force PATTERN to match only whole words
-F, --fixed-strings PATTERN is a set of newline-separated fixed strings
-f, --file=FILE obtain PATTERN from FILE
-v, --invert-match select non-matching lines
测试:
$cat a.txt
a
b
c
d
e
$cat b.txt
c
d
$grep -F -f a.txt b.txt
c
d
$grep -F -v -f b.txt a.txt #a是数量多的,不能反
a
b
e
comm a.txt b.txt
sort a.txt b.txt | uniq -d
2.求a跟b的差集:
grep -w -F -v -f b.txt a.txt (今天需求学习到)
grep -w -F -v -f b.txt a.txt | sort | uniq(集合要求排序)
3.并集
sort a.txt b.txt | uniq
awk '!a[$0]++' b.txt a.txt
参考:
https://blog.csdn.net/autofei/article/details/6579320
https://www.cnblogs.com/thatsit/p/6657993.html
网友评论