Skip to main content
edited tags
Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 265
Source Link
Heisenberg
  • 25
  • 1
  • 1
  • 6

Extract data from log file

I'm trying to learn how to parse files using the Linux commands and tools. I'm always confused on how to best leverage grep/awk/sed.

Here is a specific use case.

I have a log file that contains the following strings:

Config Server received a Connection Establishment with an invalid public key, closing connection. Agent Identifier: SRV3 Socket IP: 192.168.2.6
Config Server received a Connection Establishment with an invalid public key, closing connection. Agent Identifier: TESTSRV4 Socket IP: 10.1.2.3
Config Server received a Connection Establishment with an invalid public key, closing connection. Agent Identifier: SRV1 Socket IP: 192.168.2.15
Config Server received a Connection Establishment with an invalid public key, closing connection. Agent Identifier: TESTSRV2 Socket IP: 10.1.2.4

My goal is to extract the host name that appears after "Agent Identifier" and the associated IP address for each line and export them to a txt file. What would be the best way of going about it?