After a long search with no success, I've come here for some help. I have two files: a.txt - contains a list of id strings b.txt - contains a list of id range policies
For instance:
a.txt:
AC0359
AC0360
AC0361
AC0362
AC0369
AC0372
AC0374
AC0376
AC0380
BD0381
BD0384
BD0386
BD0389
BD0390
BD0392
BD0393
EF0394
EF0395
EF0398
EF0402
EF0404
EF0409
EF0410
b.txt:
from="AC0000" to="AC0400"
from="BD0300" to="BD0700"
from="EF0400" to="EF1000"
from="GT0000" to="GT2700"
I would like to know for each of the id strings listed in a.txt, if it is within one of the range policies listed in b.txt. I have been trying to find a solution to this for quite some time, so I really appreciate the help.
This is what I have done so far:
found_range=false
while read barcode; do
while read range_line <&3; do
if [[ $range_line == from=* && $found_range = false ]]
then
start_range=$(echo $range_line | cut -d '"' -f 2);
end_range=$(echo $range_line | cut -d '"' -f 4);
if [[ ! "$barcode" < "$start_range" && ! "$barcode" > "$end_range" ]]
then
echo "$barcode is between the range $start_range and $end_range"
fi
fi
done 3<b.txt
done <a.txt
Thanks!
我能够解决这个问题,我的解决方案是在编辑的答案中。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.