1
I'm strugling with this. I'm trying to edit the next 6 lines after a match, by adding text before each lines, and double quotes before and after the existing number on each lines.
What my file look like:
"data": [
4,
15,
43,
10,
60,
45
What I'm trying to get as output:
"data": [
"stuff": "4",
"stuff": "15",
"stuff": "20",
"stuff": "13",
"stuff": "4",
"stuff": "25",
I've trying this:
sed '/"data"/{N;N;N;N;N;s/\([0-9][0-9]\)/"stuff": "\1"/}'
But it seems to only edit second line after match. I'm not an expert so I can't figure this out. Any idea / help would be greatly appeciated.
Does it have to be
sed
, or have you considered a tool that actually understands JSON structure such asjq
? – user1686 – 2019-06-06T13:02:20.617Note that in JSON, you also need to change
[
to{
. – choroba – 2019-06-06T13:10:49.8201I can use any tool, including those who needs some kind of install, as long as it can run on a debian 9. But what I'm trying to achieve with this regexp editing is to convert that json to SQL statement in order to insert it into a database. I found several ways to do that, but each needs flat json; and this is why I'm trying to insert statements before each line that doesn't have one. – Roxxxance – 2019-06-06T15:06:19.620