[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Sheflug] Re: HTML Logs



And Lo! The Great Prophet " Richard Ibbotson" uttered these words of wisdom:
> Hi
>

Hi :)

Do you have an undying need to use sed? As this is a really nice job for
awk...


#!/bin/sh

ls -l | awk -v thisdir="`pwd`" '
BEGIN {
        print "Content-type: text/html"
        print ""
        print "<html>"
        print "<body>"
        print "<h1>Files in " thisdir "</h1>"
        print "<table>"
}

{
        print "<tr>"
        printf
("<td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s %s
%s</td><td>%s</td>\n", $1, $2, $3, $4, $5, $6, $7, $8, $9)
        print "</tr>"
}

END {
        print "</table>"
        print "</body>"
        print "</html"
}
'
## end of script

It could be enhanced a little to remove the "total" line of line 1, but
that's the bare bones of it. awk automatically splits into fields, so each
column of the ls output is $<fieldnumber> ... so permissions are $1, size
is $5, the date is in $6, $7 and $8 ... etc.

How it all ties together beyond that is an exercise for the reader :)

Chris...

-- 
\ Chris Johnson                 \
 \ cej [at] nightwolf.org.uk          \
  \ http://cej.nightwolf.org.uk/  ~-----------------------------------+
   \ Redclaw chat - http://redclaw.org.uk - telnet redclaw.org.uk 2000 \____

___________________________________________________________________

Sheffield Linux User's Group -
http://www.sheflug.co.uk/mailfaq.html

  GNU the choice of a complete generation.