Re: tar -v output kompatibel zu GNU tar?

From: Dominik Brettnacher <domi(at)saargate.de>
Date: Mon, 26 Jul 1999 17:24:17 +0200 (CEST)

On Tue, 20 Jul 1999, thomas(at)visionaire.ping.de wrote:

> >> Gibt es irgendeine Möglichkeit, die Ausgabe von tar tv irgendwie so
> >> hinzubekommen, daß sie kompatibel zu der von GNU tar (1.13) ist?
> Nimm^H^H^H^Hman awk. Fuer so relativ einfache Uebungen ist es ausgesprochen
> unkompliziert und sieht nicht so komisch aus wie Perl. :-)

Ich habe nun doch Perl genommen: Localization ist dort nicht so schwierig
wie bei awk. Mein Versuch sieht so aus:

#!/usr/bin/perl
# converts output of BSD tar(1) into GNU tar compatible format
# tries to support localization
# bug reports are welcome!

# Version 0.01 26.07.1999 Dominik Brettnacher <domi(at)saargate.de>

# we need POSIX::strftime to find out the national abbreviations for
# month names (used by BSD tar)
use POSIX qw(strftime);
for(0..11)
{
        $Month{POSIX::strftime("%b", 0, 0, 0, 1, $_, 0)} = $_ + 1;
}

while(<>)
{
        m/^(.*) (.{6}) ([0-9 ]{2}:\d{2}) (\d{4}) (.*)/ || die "regular expression did not match, please report";
        
        ($day,$month) = month_or_mday_first($2);

        printf("%s %i-%02i-%02i %s %s\n",$1,$4,$Month{$month},$day,$3,$5);
}

# BSD tar uses a quite "different" way to output the date, roughly:
# $date = strftime("%c", ...);
# $date = substr($date,4,12) . " " . substr($date,20,4);
# as it uses localization, we must try to find out whether mday is printed
# before or after the month name itself. this seems to be a solution:
sub month_or_mday_first
{
        if($_[0] =~ m/([0-9 ]{2}) (.{3})/)
        {
                return ($1, $2);
        }
        elsif($_[0] =~ m/(.{3}) ([0-9 ]{2})/)
        {
                return ($2, $1);
        }
        else
        {
                die "invalid date format $_[0]";
        }
}

-- 
Dominik - http://www.saargate.de/~domi/
To Unsubscribe: send mail to majordomo(at)de.FreeBSD.org
with "unsubscribe de-bsd-questions" in the body of the message
Received on Mon 26 Jul 1999 - 21:02:55 CEST

search this site