The UNIC utility 'comm' allows case insensitivity in BSD, but not Linux (via the -i flag). How can I get it on Linux?

I use the excellent UNIX command-line utility "comm" in an application that I developed on the BSD platform (OSX). When I deployed to my Linux server, I found that, unfortunately, the Ubuntu Linux utility 'comm' does not accept the -i flag to indicate that strings should be case insensitive. Apparently, the -i option is not required for the POSIX standard.

So ... I'm bound. I really need the -i option, which works so well on BSD. I went so far as to try to compile the BSD comm.c source code in a Linux box, but I got:

http://svn.freebsd.org/viewvc/base/user/luigi/ipfw3-head/usr.bin/comm/comm.c?view=markup&pathrev=200559

me@host:~$ gcc comm.c 
comm.c: In function ‘getline’:
comm.c:195: warning: assignment makes pointer from integer without a cast
comm.c: In function ‘wcsicoll’:
comm.c:264: warning: assignment makes pointer from integer without a cast
comm.c:270: warning: assignment makes pointer from integer without a cast
/tmp/ccrvPbfz.o: In function `getline':
comm.c:(.text+0x421): undefined reference to `reallocf'
/tmp/ccrvPbfz.o: In function `wcsicoll':
comm.c:(.text+0x691): undefined reference to `reallocf'
comm.c:(.text+0x6ef): undefined reference to `reallocf'
collect2: ld returned 1 exit status

Does anyone have any suggestions on how to get a version of a command on Linux that supports 'comm -i'?

Thank!

+3
source share
4 answers

You can add the following to comm.c:

void *reallocf(void *ptr, size_t size)
{
    void *ret = realloc(ptr, size);
    if (ret == NULL) {
        free(ptr);
    }
    return ret;
}

Then you can compile it. Be sure to comm.chave one #include <stdlib.h>in it (this probably does it already).

The reason the compilation fails is because BSD comm.cuses one reallocf(), which is not a standard C function. But it's easy to write.

+1
source

@OP, , src. . , ( ) , tr, comm.

tr '[A-Z]' '[a-z]' <file1 > temp1
tr '[A-Z]' '[a-z]' <file2 > temp2
comm temp1 temp2
+1

- - , Linux, 'comm -i'?

; , join? -i Linux...

0

You can try to bypass both files and pass them to uniq -c -i. It will display all rows in both files with the number of occurrences in the first column. As long as the source files do not have duplicate rows, all rows with the first column> 1 are lines common to both files.

Hope this helps!

0
source

Source: https://habr.com/ru/post/1730348/


All Articles