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]*>);

--
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [Fedora Magazine]     [Fedora News]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Maintainers]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Legacy]     [Fedora Desktop]     [Fedora Fonts]     [ATA RAID]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [SSH]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Centos]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Tux]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Asterisk PBX]     [Fedora Sparc]     [Fedora Universal Network Connector]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux