I just wanna to substract one CSV-File from another one, but not if the lines are the same. Instead of comparing the lines I’d like to look if the lines matching in one field.
e.g. the first file
EMAIL;NAME;SALUTATION;ID
foo@bar.com;Foo;Mr;1
bar@foo.com;Bar;Ms;2
and the second file
EMAIL;NAME
foo@bar.com;Foo
the resultfile should be
EMAIL;NAME;SALUTATION;ID
bar@foo.com;Bar;Ms;2
I think u know what I mean 😉
How is that possible in bash? It’s easy for me doing this in Java, but I realy like to learn how to do that in bash. Also I can substract by comparing the lines using sort
#! / bin / bash
echo "Substracting Files..."
sort "/tmp/list1.csv" "/tmp/list2.csv" "/tmp/list2.csv" | uniq -u >> /tmp/subList.csv
echo "Files successfully substracted."
But the lines arn’t the same tuple. So I have to compare line with keys.
Any suggestions? Thanks a lot.. Nils
One possible solution coming to my mind is this one (working with bash):
That means:
cut -d ";" -f1 /tmp/list2.csv: Extract the first column of the second file.grep -f some_file: Use a file as pattern source.<(some_command): This is a process substitution. It executes the command and feeds the output to a named pipe which then can be used as file input togrep -f.grep -v: Print only the lines not matching the pattern(s).