# Aim is to take a multiline file in the following format and make MySQL insert statement from it. End result aim is something similar to outputting: -
insert into ansible_db (ip, version) values ("$ip", "$version")
File contents
ok: [192.168.0.214] => {s "msg": "4.0.3"s}
ok: [192.168.0.210] => {s "msg": "4.0.8"s}
ok: [192.168.0.208] => {s "msg": "4.3.4"s}
The following greps get the IP's and message out appropriately: -
$ip=grep -oE '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}'
$version= grep -oP '(?<=\"\: \").*(?=\"s})' #format of the message will vary going forward.
But I can't see an example online of how to output the entire line with the variables being generated from the greps.