Ubuntu Pastebin

Paste from reelin at Mon, 25 Sep 2017 11:14:20 +0000

Download as text
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# 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. 
Download as text