Skip to content

Instantly share code, notes, and snippets.

@kozross
Last active March 5, 2016 03:09
Show Gist options
  • Save kozross/d44cb156f0ef1c9c895a to your computer and use it in GitHub Desktop.
Save kozross/d44cb156f0ef1c9c895a to your computer and use it in GitHub Desktop.
#!/usr/bin/awk -f
BEGIN {
FS=OFS=","
# edibility
translation[1, "p"] = "poisonous"
translation[1, "e"] = "edible"
# cap-shape
translation[2, "b"] = "bell"
translation[2, "c"] = "conical"
translation[2, "x"] = "convex"
translation[2, "f"] = "flat"
translation[2, "k"] = "knobbed"
translation[2, "s"] = "sunken"
# cap-surface fix
translation[3, "f"] = "fibrous"
translation[3, "g"] = "grooves"
translation[3, "y"] = "scaly"
translation[3, "s"] = "smooth"
# cap-colour fix
translation[4, "n"] = "brown"
translation[4, "b"] = "buff"
translation[4, "c"] = "cinnamon"
translation[4, "g"] = "grey"
translation[4, "r"] = "green"
translation[4, "p"] = "pink"
translation[4, "u"] = "purple"
translation[4, "e"] = "red"
translation[4, "w"] = "white"
translation[4, "y"] = "yellow"
}
{for (i = 1; i <= 4; i++) if ((i, $i) in translation) $i = arr[i, $i]}
{print}
@kozross
Copy link
Author

kozross commented Mar 5, 2016

Data fragment:

p,x,s,n,t,p,f,c,n,k,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,y,t,a,f,c,b,k,e,c,s,s,w,w,p,w,o,p,n,n,g
e,b,s,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,n,m
p,x,y,w,t,p,f,c,n,n,e,e,s,s,w,w,p,w,o,p,k,s,u
e,x,s,g,f,n,f,w,b,k,t,e,s,s,w,w,p,w,o,e,n,a,g
e,x,y,y,t,a,f,c,b,n,e,c,s,s,w,w,p,w,o,p,k,n,g
e,b,s,w,t,a,f,c,b,g,e,c,s,s,w,w,p,w,o,p,k,n,m
e,b,y,w,t,l,f,c,b,n,e,c,s,s,w,w,p,w,o,p,n,s,m
p,x,y,w,t,p,f,c,n,p,e,e,s,s,w,w,p,w,o,p,k,v,g
e,b,s,y,t,a,f,c,b,g,e,c,s,s,w,w,p,w,o,p,k,s,m

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment