UNIX“通讯”实用程序允许在 BSD 中不区分大小写,但在 Linux 中不允许(通过 -i 标志)。我怎样才能在 Linux 中得到它?
我在 BSD 平台 (OSX) 上开发的应用程序中使用了出色的 UNIX“comm”命令行实用程序。当我部署到我的 Linux 生产服务器时,我遗憾地发现 Ubuntu Linux 的“comm”实用程序没有使用 -i 标志来指示应该不区分大小写地比较这些行。显然 POSIX 标准不需要 -i 选项。
所以...我陷入了困境。我确实需要在 BSD 上运行良好的 -i 选项。我已经尝试在 Linux 机器上编译 BSD comm.c 源代码,但我得到:
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
有人对如何在 Linux 上获取支持“comm -i”的 comm 版本有任何建议吗?
谢谢!
I'm using the excellent UNIX 'comm' command line utility in an application which I developed on a BSD platform (OSX). When I deployed to my Linux production server I found out that sadly, Ubuntu Linux's 'comm' utility does not take the -i flag to indicate that the lines should be compared case-insensitive. Apparently the POSIX standard does not require the -i option.
So... I'm in a bind. I really need the -i option that works so well on BSD. I've gone so far to try to compile the BSD comm.c source code on the Linux box but I got:
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 as to how to get a version of comm on Linux that supports 'comm -i'?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以在
comm.c
中添加以下内容:然后您应该能够编译它。确保comm.c中包含
#include
(它可能已经这样做了)。编译失败的原因是 BSD
comm.c
使用reallocf()
这不是标准 C 函数。但写起来很容易。You can add the following in
comm.c
:You should be able to compile it then. Make sure
comm.c
has#include <stdlib.h>
in it (it probably does that already).The reason your compilation fails is because BSD
comm.c
usesreallocf()
which is not a standard C function. But it is easy to write.@OP,没有必要花那么大的篇幅来进行您自己的 src 代码编译。这是一个替代建议。由于您希望不区分大小写,因此在将文件传递给 comm 之前,您可以使用其他工具(例如
tr
)将两个文件中的大小写转换为小写(或大写)。@OP ,there's no need to go to such length as to do your own src code compilation . Here's an alternative suggestion. Since you want case insensitive, you can just convert the cases in both files to lower (or upper case) using another tool such as
tr
before you pass the files to comm.您可以尝试 cat 这两个文件并将它们通过管道传输到 uniq -c -i。它将显示两个文件中的所有行,并在第一列中显示出现次数。只要原始文件没有重复的行,则第一列 >1 的所有行都是两个文件共有的行。
希望有帮助!
You could try to cat both files and pipe them to uniq -c -i. It'll show all lines in both files, with the number of appearances in the first column. As long as the original files don't have repeated lines, all lines with the first column >1 are lines common to both files.
Hope it helps!
不完全是这样;但是您是否检查过
join
实用程序是否可以满足您的要求?这个确实在 Linux 上有-i
选项...Not quite that; but have you checked if your requirements could be satisfied by the
join
utility? This one does have the-i
option on Linux...