Wikipedia:Reference desk/Archives/Computing/2020 December 14
Computing desk | ||
---|---|---|
< December 13 | << Nov | December | Jan >> | Current desk > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is a transcluded archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
December 14
editdifference of files
editIs there a Unix command that can compare two sorted files and output only those lines that are in file A and not in file B? (If not, I can easily write a Python program to do it.) —Tamfang (talk) 02:10, 14 December 2020 (UTC)
- Do you want to see lines from B that are not in A? RudolfRed (talk) 03:44, 14 December 2020 (UTC)
- You can use the
comm
command:comm -23 A B
Graeme Bartlett (talk) 04:17, 14 December 2020 (UTC)- If the lines in file A are not unique, you may still see lines that are in file B but with a lower multiplicity. It is a bit like bag subtraction. If the multiplicity of a line in file A equals mA and that in file B is mB, then the number in the output is equal to 0 if mA ≤ mB, and is mA − mB otherwise (truncated subtraction). --Lambiam 12:22, 14 December 2020 (UTC)
- Good point. If that's an issue and you really want lines in A that are not in B at all, you can strip out the duplicate lines using
uniq
(or by usingsort -u
in the first place) before comparing the files. But then you won't know how many times each line that is not in B occurs in A. You may prefer to usefgrep -v -x -f B A
(also known asgrep -F -v -x -f B A
). However, this method does not take advantage of the files being sorted, so it needs to hold the whole of file B in memory while it runs through file A, which may be problematic if B is a large file. --174.95.161.129 (talk) 21:43, 14 December 2020 (UTC)- I am not sure that is a valid concern anymore, with
mmap(2)
. Elizium23 (talk) 21:49, 14 December 2020 (UTC)- "May" be. --174.95.161.129 (talk) 22:20, 14 December 2020 (UTC)
- I am not sure that is a valid concern anymore, with
- Good point. If that's an issue and you really want lines in A that are not in B at all, you can strip out the duplicate lines using
- If the lines in file A are not unique, you may still see lines that are in file B but with a lower multiplicity. It is a bit like bag subtraction. If the multiplicity of a line in file A equals mA and that in file B is mB, then the number in the output is equal to 0 if mA ≤ mB, and is mA − mB otherwise (truncated subtraction). --Lambiam 12:22, 14 December 2020 (UTC)
- Thank you,
comm
did the trick – once I made sure the files were sorted the same way! —Tamfang (talk) 03:11, 15 December 2020 (UTC)
- Thank you,
how to set make file to compile by c11 standards?
editI'm trying to compile my file with the following makefile:
obj-m := message_slot.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) CFLAGS=-O3 -std=c++0x -pg -D_DEBUG -g -c -Wall
all: $(MAKE) -C $(KDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KDIR) M=$(PWD) clean
But I keep this getting this error:
/home/eran/CLionProjects/tau_os_ex3/message_slot.c:29:5: warning: ISO C90 forbids mixed declarations and code [-Wdeclaration-after-statement] How can I set the standard to c11 for good? --Exx8 (talk) 22:57, 14 December 2020 (UTC)
- @Exx8: According to [1] use -std=c11. RudolfRed (talk) 01:09, 15 December 2020 (UTC)