Wednesday, November 16, 2011

All Mobile user-agent Strings in a Text File

WURFL is a great project dedicated to collecting data on wireless/mobile devices. If you just want a list of the user-agent strings, though, it is quite a bit of XML to sift through. You could parse it, or just convert it to a text file list of mobile user-agents. If you are doing the latter, you could use this script I wrote:


if [ $# -eq 0 ]
  echo "Download and extract the latest wurfl.xml from"
  echo "then use this script to extract the wireless user agent strings."
  echo ""
  echo "usage: wurfltxt wurfl.xml"
  exit 1

if [ ! -f "$1" ]
  echo "the first argument must be a valid path to wurfl.xml"
  exit 1

grep user_agent $1 > wurfl.txt
sed 's/.*user_agent="//g' wurfl.txt > wurfl2.txt
sed 's/"\ fall_back.*//g' wurfl2.txt > wurfl.txt
rm wurfl2.txt
sort wurfl.txt > wurfl_sorted.txt
rm wurfl.txt
mv wurfl_sorted.txt wurfl.txt
echo Created wurfl.txt

Save that to a file called wurfltxt and then:
chmod +x wurfltxt
wurfltxt /path/to/wurfl.xml
and it will generate a wurfl.txt file containing just the complete WURFL list of mobile device user-agents.

No comments: