comm

逐行比较两个已排序的文件并写入标准输出

语法

  comm [options]... File1 File2

选项

-1   不显示在第一个文件出现的内容
-2   不显示在第二个文件中出现的内容
-3   不显示同时在两个文件中都出现的内容

例子

$ comm -23 <(sort words.txt | uniq) <(sort countries.txt | uniq)

如果文件words.txt包含countries.txt的子集,那么上面的内容将不返回任何内容。
如果文件words.txt包含countries.txt中不存在的项目,则上述内容将返回这些唯一项目。

要返回words.txt和countries.txt中的行,请使用:

$ comm -12 <(sort words.txt | uniq) <(sort countries.txt | uniq)

假如文件a.txt有以下3行

 aaaa
 bb
 cc

假如文件b.txt有以下3行

 aaaa
 xx
 oo

比较两个文件

 $ comm a.txt b.txt
输出: 第一列  第二列 第三列
                    aaaa
      bb
      cc     
             xx
             oo

输出的第一列只包含在a.txt中出现的行,第二列包含在b.txt中出现的行,第三列包含在a.txt和b.txt中相同的行。各列是以制表符(\t)作为定界符

打印两个文件的相同的行

  $comm a.txt b.txt -1 -2
  aaaa

打印出两个文件中不相同的行,sed ‘s/^\t//’ 是将制表符(\t)删除,以便把两列合并成一列。

  $comm a.txt b.txt -3 | sed 's/^\t//'
  bb
  cc 
  xx
  oo   

打印a.txt中不同

 $ comm a.txt b.txt -2 -3
 bb
 cc

打印b.txt中不同

 $ comm a.txt b.txt -1 -3
 xx
 oo

comm 命令实例:

linux命令:comm -23 file2 file1 file1 file2 -23 comm comm -23 file2 file1rootopen.com
linux命令:comm -23 file2 file1 file1 file2 -23 comm comm -23 file2 file1rootopen.com
2019-01-06 22:19:04

linux命令:comm -13 ItemsListtoAvoid.txt AllItemsList.txt> ItemsDifference.txt ItemsDifference.txt AllItemsList.txt> ItemsListtoAvoid.txt -13 comm comm -13 ItemsListtoAvoid.txt AllItemsList.txt> ItemsDifference.txtrootopen.com
linux命令:comm -13 ItemsListtoAvoid.txt AllItemsList.txt> ItemsDifference.txt ItemsDifference.txt AllItemsList.txt> ItemsListtoAvoid.txt -13 comm comm -13 ItemsListtoAvoid.txt AllItemsList.txt> ItemsDifference.txtrootopen.com
2018-11-02 23:12:58

linux命令:comm -12 <(sort -u File1) <(sort -u File2) File2) -u <(sort File1) -u <(sort -12 comm comm -12 <(sort -u File1) <(sort -u File2)rootopen.com
linux命令:comm -12 <(sort -u File1) <(sort -u File2) File2) -u <(sort File1) -u <(sort -12 comm comm -12 <(sort -u File1) <(sort -u File2)rootopen.com
2018-09-11 09:55:30

linux命令:comm file1 file2 file2 file1 comm comm file1 file2rootopen.com
linux命令:comm file1 file2 file2 file1 comm comm file1 file2rootopen.com
2018-08-22 22:30:29

linux命令:comm recipe.txt shopping-list.txt shopping-list.txt recipe.txt comm comm recipe.txt shopping-list.txtrootopen.com
linux命令:comm recipe.txt shopping-list.txt shopping-list.txt recipe.txt comm comm recipe.txt shopping-list.txtrootopen.com
2018-07-27 22:13:31

linux命令:command | pbcopy && pbpaste pbpaste && pbcopy | command command | pbcopy && pbpasterootopen.com
linux命令:command | pbcopy && pbpaste pbpaste && pbcopy | command command | pbcopy && pbpasterootopen.com
2017-12-30 23:06:48

linux命令:comm -1 -2 <(sort file1) <(sort file2) file2) <(sort file1) <(sort -2 -1 comm comm -1 -2 <(sort file1) <(sort file2)rootopen.com
linux命令:comm -1 -2 <(sort file1) <(sort file2) file2) <(sort file1) <(sort -2 -1 comm comm -1 -2 <(sort file1) <(sort file2)rootopen.com
2018-04-24 13:04:48

linux命令:command !$ !$ command command !$rootopen.com
linux命令:command !$ !$ command command !$rootopen.com
2018-01-04 13:38:48

linux命令:command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp tmp rm && logfile.txt > tmp && tmp >> logfile.txt cat && tmp > command command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmprootopen.com
linux命令:command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmp tmp rm && logfile.txt > tmp && tmp >> logfile.txt cat && tmp > command command > tmp && cat logfile.txt >> tmp && tmp > logfile.txt && rm tmprootopen.com
2018-03-25 01:06:48

linux命令:command | figlet figlet | command command | figletrootopen.com
linux命令:command | figlet figlet | command command | figletrootopen.com
2018-04-17 20:59:48

linux命令:command ps -Hacl -F S -A f f -A S -F -Hacl ps command command ps -Hacl -F S -A frootopen.com
linux命令:command ps -Hacl -F S -A f f -A S -F -Hacl ps command command ps -Hacl -F S -A frootopen.com
2018-05-19 14:08:48

linux命令:command -geometry 120x30+1280+0 120x30+1280+0 -geometry command command -geometry 120x30+1280+0rootopen.com
linux命令:command -geometry 120x30+1280+0 120x30+1280+0 -geometry command command -geometry 120x30+1280+0rootopen.com
2018-04-26 15:00:48

linux命令:command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; } } -r; -p xxd | 6661696c626f61742e2e2e0a echo { command_not_found_handle() command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; }rootopen.com
linux命令:command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; } } -r; -p xxd | 6661696c626f61742e2e2e0a echo { command_not_found_handle() command_not_found_handle() { echo 6661696c626f61742e2e2e0a | xxd -p -r; }rootopen.com
2018-04-01 14:12:48

linux命令:command | sed -n '1,/regex/p' '1,/regex/p' -n sed | command command | sed -n '1,/regex/p'rootopen.com
linux命令:command | sed -n '1,/regex/p' '1,/regex/p' -n sed | command command | sed -n '1,/regex/p'rootopen.com
2018-06-09 16:33:48

linux命令:command | sed '/regex/q' '/regex/q' sed | command command | sed '/regex/q'rootopen.com
linux命令:command | sed '/regex/q' '/regex/q' sed | command command | sed '/regex/q'rootopen.com
2018-03-12 10:44:48

linux命令:comment() { echo "" > /dev/null; } } /dev/null; > "" echo { comment() comment() { echo "" > /dev/null; }rootopen.com
linux命令:comment() { echo "" > /dev/null; } } /dev/null; > "" echo { comment() comment() { echo "" > /dev/null; }rootopen.com
2018-04-29 20:18:48

linux命令:comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/' 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e sed | file2 file1 comm comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/'rootopen.com
linux命令:comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/' 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e sed | file2 file1 comm comm file1 file2 | sed -e 's/^[^\t].*/\x1b[33m&\x1b[0m/' -e 's/^\t[^\t].*/\x1b[36m&\x1b[0m/' -e 's/^\t\t[^\t].*/\x1b[32m&\x1b[0m/'rootopen.com
2018-05-18 12:28:48

linux命令:command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q' *PID/d;10q' '/^ -u -A|sed -vsz k pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args wwo ps command command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'rootopen.com
linux命令:command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q' *PID/d;10q' '/^ -u -A|sed -vsz k pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args wwo ps command command ps wwo pid,user,group,vsize:8,size:8,sz:6,rss:6,pmem:7,pcpu:7,time:7,wchan,sched=,stat,flags,comm,args k -vsz -A|sed -u '/^ *PID/d;10q'rootopen.com
2018-03-13 11:55:48

linux命令:command | ssh myHost xsel -i --display :0 :0 --display -i xsel myHost ssh | command command | ssh myHost xsel -i --display :0rootopen.com
linux命令:command | ssh myHost xsel -i --display :0 :0 --display -i xsel myHost ssh | command command | ssh myHost xsel -i --display :0rootopen.com
2018-06-06 00:22:48

linux命令:command &! &! command command &!rootopen.com
linux命令:command &! &! command command &!rootopen.com
2018-03-24 15:45:48

linux命令:comm --nocheck-order -31 -31 --nocheck-order comm comm --nocheck-order -31rootopen.com
linux命令:comm --nocheck-order -31 -31 --nocheck-order comm comm --nocheck-order -31rootopen.com
2018-01-28 12:51:48

linux命令:command & echo $! $! echo & command command & echo $!rootopen.com
linux命令:command & echo $! $! echo & command command & echo $!rootopen.com
2018-02-10 17:46:48

linux命令:comm -12 FILE1.sorted FILE2.sorted > common common > FILE2.sorted FILE1.sorted -12 comm comm -12 FILE1.sorted FILE2.sorted > commonrootopen.com
linux命令:comm -12 FILE1.sorted FILE2.sorted > common common > FILE2.sorted FILE1.sorted -12 comm comm -12 FILE1.sorted FILE2.sorted > commonrootopen.com
2018-02-25 17:47:48

linux命令:command >&- >&- command command >&-rootopen.com
linux命令:command >&- >&- command command >&-rootopen.com
2018-04-10 21:01:48

linux命令:command -v bash bash -v command command -v bashrootopen.com
linux命令:command -v bash bash -v command command -v bashrootopen.com
2018-05-09 17:54:48

linux命令:comm -13 <(sort file1) <(sort file2) > file-new file-new > file2) <(sort file1) <(sort -13 comm comm -13 <(sort file1) <(sort file2) > file-newrootopen.com
linux命令:comm -13 <(sort file1) <(sort file2) > file-new file-new > file2) <(sort file1) <(sort -13 comm comm -13 <(sort file1) <(sort file2) > file-newrootopen.com
2018-06-09 17:09:48

linux命令:command W :execute ':silent w !sudo tee % > /dev/null' | :edit! :edit! | /dev/null' > % tee !sudo w ':silent :execute W command command W :execute ':silent w !sudo tee % > /dev/null' | :edit!rootopen.com
linux命令:command W :execute ':silent w !sudo tee % > /dev/null' | :edit! :edit! | /dev/null' > % tee !sudo w ':silent :execute W command command W :execute ':silent w !sudo tee % > /dev/null' | :edit!rootopen.com
2018-02-08 14:48:48

linux命令:command > >(tee stdout.log) 2> >(tee stderr.log >&2) >&2) stderr.log >(tee 2> stdout.log) >(tee > command command > >(tee stdout.log) 2> >(tee stderr.log >&2)rootopen.com
linux命令:command > >(tee stdout.log) 2> >(tee stderr.log >&2) >&2) stderr.log >(tee 2> stdout.log) >(tee > command command > >(tee stdout.log) 2> >(tee stderr.log >&2)rootopen.com
2018-04-05 18:59:48

linux命令:comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -c -c '$_=chr($_)'|od -pe 127|sort)|perl 0 <(seq -u) -c9-|sort dummy.txt|cut -tu1 -vw1 <(od -13 comm comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -crootopen.com
linux命令:comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -c -c '$_=chr($_)'|od -pe 127|sort)|perl 0 <(seq -u) -c9-|sort dummy.txt|cut -tu1 -vw1 <(od -13 comm comm -13 <(od -vw1 -tu1 dummy.txt|cut -c9-|sort -u) <(seq 0 127|sort)|perl -pe '$_=chr($_)'|od -crootopen.com
2018-05-05 04:28:48

linux命令:command <<< word word <<< command command <<< wordrootopen.com
linux命令:command <<< word word <<< command command <<< wordrootopen.com
2018-03-29 20:57:48

linux命令:command 3>&1 1>&2 2>&3 | tee file file tee | 2>&3 1>&2 3>&1 command command 3>&1 1>&2 2>&3 | tee filerootopen.com
linux命令:command 3>&1 1>&2 2>&3 | tee file file tee | 2>&3 1>&2 3>&1 command command 3>&1 1>&2 2>&3 | tee filerootopen.com
2018-04-09 14:23:48

linux命令:command 3>&1 1>&2 2>&3 | tee -a file file -a tee | 2>&3 1>&2 3>&1 command command 3>&1 1>&2 2>&3 | tee -a filerootopen.com
linux命令:command 3>&1 1>&2 2>&3 | tee -a file file -a tee | 2>&3 1>&2 3>&1 command command 3>&1 1>&2 2>&3 | tee -a filerootopen.com
2018-05-05 14:16:48

linux命令:command -v <command> <command> -v command command -v <command>rootopen.com
linux命令:command -v <command> <command> -v command command -v <command>rootopen.com
2018-03-03 04:55:48

linux命令:command_line 2>&1 | tee -a output_file output_file -a tee | 2>&1 command_line command_line 2>&1 | tee -a output_filerootopen.com
linux命令:command_line 2>&1 | tee -a output_file output_file -a tee | 2>&1 command_line command_line 2>&1 | tee -a output_filerootopen.com
2018-04-11 11:18:48

linux命令:command foo bar | sudo tee /etc/write-protected > /dev/null /dev/null > /etc/write-protected tee sudo | bar foo command command foo bar | sudo tee /etc/write-protected > /dev/nullrootopen.com
linux命令:command foo bar | sudo tee /etc/write-protected > /dev/null /dev/null > /etc/write-protected tee sudo | bar foo command command foo bar | sudo tee /etc/write-protected > /dev/nullrootopen.com
2018-04-08 22:49:48

linux命令:command ${MYVAR:+--someoption=$MYVAR} ${MYVAR:+--someoption=$MYVAR} command command ${MYVAR:+--someoption=$MYVAR}rootopen.com
linux命令:command ${MYVAR:+--someoption=$MYVAR} ${MYVAR:+--someoption=$MYVAR} command command ${MYVAR:+--someoption=$MYVAR}rootopen.com
2018-01-18 13:40:48

linux命令:command systemctl --no-page --no-legend --plain -t service --state=running --state=running service -t --plain --no-legend --no-page systemctl command command systemctl --no-page --no-legend --plain -t service --state=runningrootopen.com
linux命令:command systemctl --no-page --no-legend --plain -t service --state=running --state=running service -t --plain --no-legend --no-page systemctl command command systemctl --no-page --no-legend --plain -t service --state=runningrootopen.com
2018-01-16 08:18:48

linux命令:comm -1 -2 <(sort file1) <(sort file2) |& tee outputfile outputfile tee |& file2) <(sort file1) <(sort -2 -1 comm comm -1 -2 <(sort file1) <(sort file2) |& tee outputfilerootopen.com
linux命令:comm -1 -2 <(sort file1) <(sort file2) |& tee outputfile outputfile tee |& file2) <(sort file1) <(sort -2 -1 comm comm -1 -2 <(sort file1) <(sort file2) |& tee outputfilerootopen.com
2018-01-16 17:22:48

Linux的Bash命令行(A-Z排序)