I'm a hacker, a free software advocate, and a student.
A day towards learning AWK
. Although I've not planned my day to learn AWK
, but it happened accidentally (or by chance ;-)). Today, I was in my practical class, and there I saw an old machine is running Fedora Core 1. I thought what I can do with that system, since the system doesn't has any development tools. It has tools without documentation. Then I thought AWK
might be there so, why not learn AWK
. Because, I've tried learning AWK previously too many times, but wasn't successful (it was not tough, but because I don't know what to do with that language). So today, I thought why not XMLify, the /etc/passwd (one of the primary target of awk
tutorials) and /etc/group. And then, I opened its infopages by executing info awk
. but oops info
is displaying its manpages. Then I recalled that on GNU/Linux machines AWK
comes GAWK
, so I did info gawk
. And started reading Getting started.
So, within half-an hour I've produced my AWK
script to XMLify /etc/passwd and /etc/group. Here I'm giving my AWK
script to /etc/passwd.
# passwd2xml.awk: An AWK script to transform /etc/passwd file into passwd.xml BEGIN { FS=":"; print "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<passwd>"; } /:/ { printf "\t<user id=\"%s\" uid=\"%s\" gid=\"%s\" home=\"%s\" comment=\"%s\" password=\"%s\" shell=\"%s\"/>\n", $1, $3, $4, $6, $5, $2, $7; } END { print "</passwd>"; }
You can execute this script and then pipe that output to xmllint to check for well-formedness of the document as shown below:
[wahjava@pc awk]$ awk -f passwd2xml.awk /etc/passwd |xmllint -
GAWK also comes for Windows and available here.
BTW, this script is not the correct way to XMLify the /etc/passwd since XMLifying needs entitifying some characters e.g. <, > etc.
200601 200602 200603 200604 200605
There are some of my webpages tooo...
This blog is [ INVALID XHTML v1.0 ] [ INVALID CSS v2.0 ]