I have a long list (~100 lines) containing lines of names of animals, where they were spotted and when named spottings. The first 3 lines could be this:
cat 1999 madagascar
dog 1827 peru
kangaroo 1995 new zealand
cat 1827 england
Now I want to match that list with another list want that goes like this:
cat
dog
kangaroo
However, I only want to get the lines that also match a given year but not a given location. For examples, with 1827 and england I've done it like this:
cat spottings | grep -i -f want | sed '/1827/I!d;/england/Id'
Now, if my yearand location are located in a string like this:
want="1827,1999,2013" # year
nonotwant="england,madagascar,peru" # location
which is made into an array like this:
want=($(echo ${want} | tr ',' '\n'))
If I would check for all elements of wantand donotwant it would be like this:
sed spottings | grep -i -f want | sed '/1827/I!d;/1999/I!d;/2013/I!d;/england/Id;/madagascar/Id;/peru/Id'
How would I check for all elements in both arrays?
wantandnonotwant? Also, the commandsed '/1827/I!d;/1999/I!dwould eliminate all lines unless they have both years on the same line. Do you, instead, want it eliminate all lines unless they have one or the other? Please clarify.