Skip to content

Instantly share code, notes, and snippets.

@jhyland87
Created May 15, 2017 16:33
Show Gist options
  • Save jhyland87/f660066ec0504a118347bf8a3f9cd32e to your computer and use it in GitHub Desktop.
Save jhyland87/f660066ec0504a118347bf8a3f9cd32e to your computer and use it in GitHub Desktop.
Basic awk script that can be used to parse a config similar to the INI layout (var = val)
#! /usr/local/bin/awk -f
# Solution by Ed Morton (http://stackoverflow.com/a/43946907/5154806)
# Example: echo -e "personal.name.first=John\npersonal.name.last\t=Doe\npersonal.other.dob=\t05/07/87\npersonal.contact.phone\t=\t602123456\npersonal.contact.email\t = \tjohn.doe@idk\nemployment.jobs.1\t\t= Company One\nemployment.jobs.2 \t =Company Two\nemployment.jobs.3\t= Company Three" | ./tst.awk
BEGIN {
FS="[\t ]*=[\t ]*"
}
{
split($1,d,/\./)
data[d[1]][d[2]][d[3]] = $2
}
END {
for (x in data)
for (y in data[x])
for (z in data[x][y])
print x, y, z, "->", data[x][y][z]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment