Re: script help request

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

 



Paul Lemmons wrote:
Try this. I am sure it could be done better but I think it will get the job done ...

Not "better" just different:

# Read pairs like "81230 jsmith" from stdin
%id = map {split} <>;

foreach (<*_d_[0-9]*>) {
    # substitute the id#: $_ is orig filename, $n is new
    ($n = $_) =~ s/_d_([0-9]+)_/_d_$id{$1}_/;

    # rename the file only if the id# is in our list
    if ($id{$1}) {
	rename($_,$n) || warn "can't rename $_: $!\n";
    } else {
	warn "unknown id '$1' in file '$_'\n";
    }
}


Or just for fun, as a one-liner:

%id=map{split}<>;($n=$_)=~s/_d_([0-9]+)_/_d_$id{$1}_/ && \
$id{$1} && print("$_>$n\n") || warn "$_:$!\n" foreach(<*_d_[0-9]*>);


[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux