简体   繁体   中英

comm command not comparing words

I am trying to learn shell programming and for that I am using ubuntu app in windows 10, I read about the comm command and as I have understood it it should be working as below

file1.txt    file2.txt
abc          abc
cde          efg
a            b
b            c

the result should be
a
cde
             abc
             b
      c
      efg

but what I am getting is

abc
a
cde            
              b
       efg
       abc
       c

this is how I used the command

comm file1.txt file2.txt

I suspect its because I am using it on a windows app but other commands such as grep uniq ps pwd... all are working fine Any help would be appreciated

Windows is not the problem here. You used comm in the wrong way. man comm states

comm - compare two sorted files line by line

Therefore, you have to sort both files first.

Use

sort file1.txt > file1sorted
sort file2.txt > file2sorted
comm file1sorted file2sorted

Or if you are using bash (not plain sh or some other shell)

comm <(sort file1.txt) <(sort file2.txt)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM