Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created March 15, 2012 03:24
Show Gist options
  • Save danmactough/2041678 to your computer and use it in GitHub Desktop.
Save danmactough/2041678 to your computer and use it in GitHub Desktop.
Bash one-liner to create JSON { shorturl: longurl } from a directory of Adjix redirects
grep "rel=\"canonical\"" * | awk '{ OFS = ""; ORS = ","; file = substr($1, 0, 4); href = match($0, /http:\/\/[^\"]+/); print "\"", file, "\": \"", substr($0, RSTART, RLENGTH), "\""}' | awk '{ OFS = ""; ORS = ""; len = length($0); print "{", substr($0, 1, len - 1), "}" }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment