Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
folks i am trying to write a bash script to restore some files from a bunch of archives.
the archive are named as follows:
Code:
ls
vzdump-qemu-201-2011_08_19-18_09_13.tgz
vzdump-qemu-202-2011_08_19-18_11_45.tgz
vzdump-qemu-203-2011_08_19-18_14_05.tgz
vzdump-qemu-3321-2011_08_19-18_16_37.tgz
vzdump-qemu-7501-2011_08_19-18_18_32.tgz
vzdump-qemu-99000-2011_08_19-18_31_24.tgz
vzdump-qemu-99101-2011_08_19-17_58_40.tgz
vzdump-qemu-99201-2011_08_19-18_01_07.tgz
vzdump-qemu-99501-2011_08_19-18_02_28.tgz
to run the tool that i need; i require to know the ID of this file.
for the first file (vzdump-qemu-201-2011_08_19-18_09_13.tgz)
this ID is 201
so i need to split/cut out the filename and get this ID for each file.
i have tried to find the solution - but i have not found many articles that described what they were doing - and instead i found a lot of pieces of bash coding that did something that i did not understand.
#!/usr/bin/perl
use strict;
use warnings;
opendir(TGZFILES, ".") or die "doesn't work $!\n";
my @file;
while (readdir TGZFILES) {
if ($_ =~ m/\.tgz/) {
@file = split "-", $_;
print "id: ", $file[2], " filename: ", $_, "\n";
}
}
just to help clarify for everyone: is the ID always the first 3 digits? or the numbers in between the 2nd dash and the 3rd dash? (ex: 99501 for the last file)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.