ffsd87
ffsd87

Reputation: 1

How to combine reg expr matches together in one output?

I would like to combine in one output from grep these two separate results. What reg expression match should I use

grep "NS" file.txt 
 ftx.domainname.example.com  3600    IN    NS    ftxns01.domainname.example.com
grep "^sdfns[0-9]" file.txt 

ftxns001-oob.domainname.example.com. 86400 IN A    192.168.30.2
ftxns001.domainname.example.com.   86400 IN A    192.168.2.2

What can I include to exclude "-oob"

The desirable end effect for me would be:

ftx.domainname.example.com  3600    IN    NS    ftxns01.domainname.example.com
ftxns001.domainname.example.com.   86400 IN A    192.168.2.2

I figured just concatenating the first two results together would give me close results however I couldn't get excluding hostnames with "-oob" in the name to work when trying grep [^oob] or [^-oob]

Upvotes: 0

Views: 31

Answers (1)

Barmar
Barmar

Reputation: 780974

You can use grep -v to exclude lines that match a pattern.

grep "^sdfns[0-9]" file.txt | grep -v -e '-oob' 

Or if you have GNU grep, you can use -P to get PCRE, and then use a negative lookahead.

grep '^sdfns\d+(?!-oob)' file.txt

[^-oob] doesn't work because that matches a single character that isn't in that list, it's not for excluding whole strings. It's the opposite of [-oob], which matches a single character that is in that set.

Upvotes: 1

Related Questions