‘comm’ command compares two files or streams. By default, ‘comm’ will always display three columns.
Number of first column indicates non-matching items of number of first file, The column number second is indicates non-matching items of second file.
Column number of third is indicates matching items of both the files. Both the files has to be in sorted order for ‘comm’ command to be execute.
Sample syntax of comm command :
# comm <file1> <file2>
Like example of comm command :
# comm test1 test2
Column of first is displays non-matching items of first file ‘file1’.
The column second is displays non-matching items of second file ‘file2’ .
And the third column indicates matching items of both the files.
To Display Single Column
If you want to output a single column, you have to specify number of the columns which are not to be display.
Sample syntax of comm command :
1.# comm -23 (To display first column)
2.# comm -13 (To display second column)
3.# comm -12 (To display third column)
Like example of comm command :
1.# comm -23 test1 test2
2.# comm -13 test1 test2
3.# comm -12 test1 test2
See your terminal after run the command, column number which needs to be display are not mentione in the ‘comm’ command.
Linux sed command and options description
‘sed’ stands for stream editor. You can use this command to edit streams (files) using regular expressions. This editing is not permanent.
Sample syntax of sed command :
# command | sed ‘s/<old word>/<new word>/’
Like example of sed command :
# echo class7 | sed 's/class/jtp/'
# echo class7 | sed 's/7/10/'
# cat test | sed 's/learn/study/'
You can see your terminal , first we have performed ‘sed’ command on a string ‘class7’ where ‘class’ is change into ‘jtp’ and 7 into 10. Then we have performed ‘sed’ command on a stream ‘test’ where ‘learn’ is converte into ‘study’.
Global Replacement with sed command
All ‘learn’ word were not edit into ‘study’. Now edit every word we have to use a global replacement ‘g’. It will edit all the specified word in a file or string.
Sample syntax of sed global replacement command :
# command | sed ‘s/<old word>/<new word>/g’
Like example of sed global replacement command :
#echo class7 class9 | sed 's/class/jtp/g'
#cat test | sed 's/learn/study/g'
you can see your terminal picture, with command “echo class7 class9 | sed ‘s/class/jtp/g’ “ all the ‘class’ is converte into ‘jtp’ and with command “cat test | sed ‘s/learn/study/g’ “ all the ‘learn’ was converte into ‘study’.
Removing A Line with sed command
The Linux d option will let you to remove a complete line from a file. You only need to specify a word from that line with ‘d’ option and that line will be delete. Since, please note that all the lines having that same word will be delete.
Sample syntax of sed removing command :
#cat <filename> | sed ‘/<word>/d’
Like example of sed removing command :
# cat test | sed ‘/jtp/d’
Above the picture, with command “cat test | sed ‘/jtp/d’ ” all lines containing word ‘jtp‘ is delete.