I'm looking for a way to do the following operation in bash:
Specify an input file (JSON)
Write each line to a new file (lines could be limited by Regex pattern, not necessary though)
Name each file after a specific JSON value in the file
In previous attempts, I tried using a simple split
(without the naming part) for the task, but it exited after a certain amount of lines. My biggest file has about 1000 lines.
Example input:
{
"stuff":
[
{ "data": "123", "filename": "abc.xml" },
{ "data": "456", "filename": "def.xml" },
{ "data": "789", "filename": "ghi.xml" }
]
}
Example output:
Contents of abc.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<data>123</data>
Contents of def.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<data>456</data>
PS: The example was simply chosen to get you an idea, though the input file resembles that of my real scenario.