Ihor Mutel
Ihor Mutel

Reputation: 1

Grep search for a string by pattern and then find part of this string inside of another file

I have log file where I look for strings like:

tail -n 1000 -f logfile.log | grep -i "host"

and then I receive strings like these:

host2 %host-DEREG: host c459.cf00.1105 is deregistered on E0/1:60.

Could I choose mac addresses from these strings and look for strings with these mac addresses inside of another file?

Upvotes: 1

Views: 192

Answers (1)

Ipor Sircer
Ipor Sircer

Reputation: 3141

There is no macaddress in your example

grep `tail -n 1000 -f logfile.log | grep -i "host" | grep -o "[a-f0-9][a-f0-9][a-f0-9][a-f0-9]\.[a-f0-9][a-f0-9][a-f0-9][a-f0-9]\.[a-f0-9][a-f0-9][a-f0-9][a-f0-9]"` anotherfile

Upvotes: 1

Related Questions