I have a multi-part grep in place that is extracting lines from router config files. The grep pulls a variety of fields that occur only once in the file, such as IP address, logging status, snmp community, etc. For this, I have a simple grep such as the following:
grep -e "ip address" -e "logging status" -e "snmp community" $file
However, I also need it to pull the first instance of a field that occurs several times in the file, in this case, the "ospf area" field. With a single grep, I can accomplish this via:
grep -m 1 "ospf area" $file
How can I perform both functions in a single grep? I'm looping over hundreds of very long files, and I'd like to keep this as efficient as possible. I'm also not married to grep for this, so I'd be interested in seeing other ideas.