Last active
May 9, 2017 22:12
-
-
Save miken32/a8ca6fa854b37ca2bb82720b181e842a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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