优化大师
在我们的开发和运营中,特别是对业务进行监控的时候,我们常常需要写一些监控shell脚本,而这些脚本需要求两个文件的共同的记录列表或者只出现在第一个文件但不出现在第二个文件的记录列表的场景,此时,comm命令则是您解决此类问题的利器和助手。 随意man comm下,可以在Linux下看到该命令的使用方法: NAME comm - compare two sorted files line by line SYNOPSIS comm [OPTION]... FILE1 FILE2 DESCRIPTION Compare sorted files FILE1 and FILE2 line by line. With no options, produce three-column output. Column one contains lines unique to FILE1, column two contains lines unique to FILE2, and column three contains lines common to both files. -1 suppress lines unique to FILE1 -2 suppress lines unique to FILE2 -3 suppress lines that appear in both files --help display this help and exit --version output version information and exit 上面是英文说明,下面简单的说明如下: 一,利用comm命令进行处理的文件必须首先通过sort命令进行排序处理并且是unix格式而非dos格式的文本文件; 二,中文说明如下: 功能说明:比较两个已排过序的文件。(使用sort排序) 语 法:comm [-123][--help][--version][第1个文件][第2个文件] 补充说明:这项指令会一列列地比较两个已排序文件的差异,并将其结果显示出来,如果没有指定任何参数,则会把结果分成3栏显示:第1栏仅是在第1个文件中出现过的记录,第2栏是仅在第2个文件中出现过的记录,第3栏则是在第1与第2个文件里都出现过的记录。若给予的文件名改为"-",则comm指令会从标准输入设备读取数据。