'Linux - "for" loop to search a list of serial numbers and display their port

A customer I'm supporting has a list of serial numbers they want to know various information about. Rather than run a single statement on each serial number by hand, I was trying to do a "for" loop, but I'm running into some snags, mainly the loop fails. However, I've confirmed doing a single command on one of the serial numbers returns what I'm looking for. Here's what I've tried:

Example loop:

$for x in /abc/spool/abc/info
>do
>echo "============================"
>echo "Searching $x"
>grep -r "CNBCNCY0KL|CNBCNCY0GN|CNBCN9G0LD"
>echo "============================"
>done

When doing a single serial number, the result looks like this:

$grep -r CNBCN9G0LD /abc/spool/abc/info
ep58:SERIAL NUMBER="CNBCN9G0LD"
$

I'm not super fluid on "for" loops, I have a basic one that I edit for almost everything I try, but I believe it's due to a limitation with "grep". Either it's crashing the loop when it fails to find the first string (delimited by a |) or its returning nothing/null because no one item has all the serial numbers (which would be disastrous if one did).

I've since manually found each serial number (had to take care of the customer first) but I'm hoping someone can help me to have a useful loop for the future.

Please let me know if I can include any further information, or how to better word my question(s) in the future.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source