#!/usr/skunk/bin/gawk -f # @(#) unixtime.gawk 1.0 93/05/11 # 92/09/12 john h. dubois iii (john@armory.com) # 93/01/27 added printing of systime() if no args given # 93/05/11 Use long date format string instead of %c in case %c doesn't work # Use gawk for systime() and strftime() BEGIN { if (ARGC == 1) print systime() else if (ARGC > 1) { if (ARGV[1] ~ "^[-+]h$") print \ "unixtime: convert UNIX times, given as the number of seconds since the\n" \ "epoch (1970 Jan 1 GMT), to a local time in human readable format.\n" \ "Usage: unixtime [-hi] [time ...]\n" \ "-h: print this help.\n"\ "-i: read times from stdin instead of processing times on the command line.\n"\ "If no arguments are given, the current epoch time is printed." else if (ARGV[1] ~ "^[-+]i$") while ((getline < "/dev/stdin") == 1) for (i = 1; i <= NF; i++) Convert($i) else for (i = 1; i < ARGC; i++) Convert(ARGV[i]) } } function Convert(S) { if (S !~ "^[0-9]+$") printf "Bad time: \"%s\".\n",S > "/dev/stderr" else print strftime("%a %b %d %T %Z %Y",S) }