perl script help
Warren Block
wblock at wonkity.com
Fri Apr 16 20:24:10 PDT 2004
On Fri, 16 Apr 2004, Shaun Friedle wrote:
> #!/usr/bin/perl
> $timezone=`date +\%z`; #Gets the offset in $timezone
> $timezone =~ s/(\+[0-9][0-9])/$1:/; #Replaces ±NN with ±NN:
> print $timezone; #Prints $timezone
The regex should allow either a plus or a minus as the first character:
s/([+-][0-9]{2})/$1:/
I like Perl a lot, and use it often, but it seems a bit much for this.
If there were easy shell substring operations... Anyway, shell-only:
date +%z | sed 's/.../&:/' # insert colon after first three chars
-Warren Block * Rapid City, South Dakota USA
More information about the freebsd-questions
mailing list