Skip to content

Instantly share code, notes, and snippets.

@miken32
Last active May 9, 2017 22:12
Show Gist options
  • Save miken32/a8ca6fa854b37ca2bb82720b181e842a to your computer and use it in GitHub Desktop.
Save miken32/a8ca6fa854b37ca2bb82720b181e842a to your computer and use it in GitHub Desktop.
#!/bin/bash
xml_head='<?xml version="1.0" charset="utf-8" standalone="yes"?>\n<directory>\n<itemlist>'
xml_tail='</itemlist>\n</directory>'
mysql -N -D asterisk -e 'SELECT name, extension FROM users ORDER BY extension' | \
awk -F"\t" -v "xh=$xml_head" -v "xt=$xml_tail" '
BEGIN {print xh}
{printf ("<item><fn>%s</fn><ln>%s</ln><ct>%d</ct></item>\n", substr($1,0,index($1," ")-1), substr($1,index($1," ")+1), $2)}
END {print xt}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment