Skip to content

Instantly share code, notes, and snippets.

@georgeOsdDev
Created September 26, 2012 14:06
Show Gist options
  • Save georgeOsdDev/3788257 to your computer and use it in GitHub Desktop.
Save georgeOsdDev/3788257 to your computer and use it in GitHub Desktop.
df as json by oneliner
df -k --portability | sed -e "s/\s\{1,\}/,/g" | awk 'BEGIN{FS=",";json = "[{"}{if (NR == 1) { for (i=1;i < NF+1;i++) { key[i] = $i}};if(NR != 1){for (i=1;i < NF;i++) { json = json "\"" key[i] "\":\"" $i "\","}; json = json "\"" key[NF] "\":\"" $NF "\"},{" }} END{ sub(/,\{$/, "", json);json = json "]";print json}' >> df.json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment