This document is to help anyone who needs to load data into a realtime database, from a text file.

Let us assume this is your complete set of data:
    "firstname": "Barack",
    "lastname": "Obama",
    "favoritepet": "cat",
    "favoritecolor": "purple"
    "firstname": "Donald",
    "lastname": "Trump",
    "favoritepet": "dog",
    "favoritecolor": "brown"
    "firstname": "Ronald",
    "lastname": "Reagan",
    "favoritepet": "bird",
    "favoritecolor": "yellow"
    "firstname": "Thomas",
    "lastname": "Jefferson",
    "favoritepet": "snake",
    "favoritecolor": "pink"
We create a file with this contents, and call it dataF.

We then build a utility script like the following, with the name utlscrpt:
#!/bin/bash

let "start = ($1-1)*4+1"
let "end = $start + 3"

sed -n "$start,$end p" $2 | \
sed '
/firstname/ {
i\
{
}
/favoritecolor/ {
a\
}
}
'
Assuming both our files (dataF and utlscrpt) are in the same directory and utlscrpt has execution permissions. In a terminal, we move to this directory, and run the command:

./utlscrpt 3 dataF


We will get the result below:
{
    "firstname": "Ronald",
    "lastname": "Reagan",
    "favoritepet": "bird",
    "favoritecolor": "yellow"
}
Therefore we can insert the third data record into the DB at /YourDBPath by running:

./utlscrpt 3 dataF | firebase database:push /YourDBPath



And we can insert all the contents of the dataF file into the DB at /YourDBPath by running in the terminal:

for i in {1..4}; do ./utlscrpt $i dataF | firebase database:push /YourDBPath; done



The above is no rocket science. There is room for improvement. But if you only need it once, that may be just enough to get the job done.

On the other hand if you plan to use it on a larger scale; it surely needs to be generalized. And you may want to include some error checking as well.


Challenge learning a new language with your iPhone

You are looking for some selected technical tutorials, to brush up you knowledge or because you would need some reminders. Have look here.