[英]loop over array in sed in bash
I have a long list (~100 lines) containing lines of names of animals, where they were spotted and when named spottings
. 我有一个包含动物的名称的线长列表(〜100线),在那里他们被发现并命名时
spottings
。 The first 3 lines could be this: 前3行可能是这样的:
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: 现在我想,以配合另一列表列表
want
是这样的:
cat
dog
kangaroo
However, I only want to get the lines that also match a given year
but not a given location
. 但是,我只想获得也匹配给定
year
但不匹配给定location
。 For examples, with 1827
and england
I've done it like this: 例如,在
1827
和england
我这样做是这样的:
cat spottings | grep -i -f want | sed '/1827/I!d;/england/Id'
Now, if my year
and location
are located in a string like this: 现在,如果我的
year
和location
位于这样的字符串中:
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 want
and donotwant
it would be like this: 如果我要检查是否
want
和donotwant
want
所有元素,它将是这样的:
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? 如何检查两个数组中的所有元素?
why not a 为什么不
fgrep -i -f want spottings | fgrep -i -f WantYear | fgrep -v -f NotWantLocation
where want
, WantYear
and NotWantLocation
are file with 1 criteria per line. 其中
want
, WantYear
和NotWantLocation
是每行1条条件的文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.