Last active
October 27, 2018 01:12
-
-
Save waltervargas/ff26fea95cf87093a6534f7bddf8cc1b to your computer and use it in GitHub Desktop.
csv to json in bash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
_csv () { | |
cat /dev/stdin <<EOF | |
"text/html","gzip","en;q=0.5","close","httpbin.org","1","curl","20" | |
"text/html","gzip","en;q=0.5","close","httpbin.org","1","curl","20" | |
"text/html","gzip","en;q=0.5","close","httpbin.org","1","curl","20" | |
"text/html","gzip","en;q=0.5","close","httpbin.org","1","curl","20" | |
"text/html","gzip","en;q=0.5","close","httpbin.org","1","curl","20" | |
EOF | |
} | |
_json () { | |
cat /dev/stdin <<EOF | |
{ | |
"headers": { | |
"Accept": "${Accept}", | |
"Accept-Encoding": "${AcceptEncoding}", | |
"Accept-Language": "${AcceptLanguage}", | |
"Connection": "${Connection}", | |
"Host": "${Host}", | |
"Upgrade-Insecure-Requests": "${UpgradeInsecureRequests}", | |
"User-Agent": "${UserAgent}", | |
"X-Imforwards": "${XImforwards}" | |
} | |
} | |
EOF | |
} | |
_csv_to_json () { | |
(IFS=, | |
read Accept \ | |
AcceptEncoding \ | |
AcceptLanguage \ | |
Connection \ | |
Host \ | |
UpgradeInsecureRequests \ | |
UserAgent \ | |
XImforwards | |
_json | |
) <<< "${1}" | |
} | |
while read row; do | |
_csv_to_json "${row//\"/}" | |
done <<< "$(_csv)" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment