I have a file like this
103710:v2HAbAFH029324:[email protected]:localhost:Sent
103821:CCFE5609E3:[email protected]:localhost:bounced
103922:DFF19609E2:[email protected]:localhost:Deferred
I need to change this to
{"randomId":{"s":"103710"},"id":{"s":"v2HAbAFH029324"},"userId":{"s":"[email protected]"},"dns":{"s":"localhost"},"status":{"s":"Sent"}}
{"randomId":{"s":"103821"},"id":{"s":"CCFE5609E3"},"userId":{"s":"[email protected]"},"dns":{"s":"localhost"},"status":{"s":"bounced"}}
{"randomId":{"s":"103922"},"id":{"s":"DFF19609E2"},"userId":{"s":"[email protected]"},"dns":{"s":"localhost"},"status":{"s":"Deferred"}}
I am thinking the code like this
while read line
do
sed -i 's/^/{"randomId":{"s":"/' test
echo $line
echo $line | grep -q ":"
[ $? -eq 0 ] && echo "/"{"id":{"s":/"
[ $? -eq 1 ] && echo "/",{"userId":{"s":/"
[ $? -eq 2 ] && echo "/",{"host":{"s":/"
[ $? -eq 3 ] && echo "/",{"status":{"s":/"
echo "$line | " ";
done < test
Adding for first occurence of : {"id":{"s": and then second occurence adding {"userId":{"s":
echo -n, to stop it from inserting newlines?