Automation Script !! Create automated archive of files based on name of file!
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Automation Script !! Create automated archive of files based on name of file!
Evening all,
I am having some difficulty with a script that I need to create. I have a folder in a Red Hat system that contains wav files (alot of wav files) they have in their names a date format YYYYMMDD so I can search for them and then create a manual archive (tar.gz). The problem is their shear number of files dating back to early 2006 this would take an age.
I basically need a script that will assess the folder based on dates and create an archive for each day of the year (or for each day that a wav file is present) of the wav files.
In short put all wav files named *YYYYMMDD*.wav into YYYYMMDD.tar.gz for each collection of files dated *YYYYMMDD*.wav.
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
I think that
ls | sed -e 's/.*\([0-9]\{8,8\}\).*[.]wav/\1' | sort | uniq
will give you the list of all needed dates. Now pipe it to a loop like
while read; do tar czf ${REPLY}.tar.gz *${REPLY}*; done
You'd better check the commands by using 'echo tar' instead of tar first. Maybe even try a dry-run.
many thanks for the quick reply. I have not even heard of sed before guess I am new to Linux, could you break down what the script does I am online trying to decifer but it could take a while.
The output from:
ls | sed -e 's/.*\([0-9]\{8,8\}\).*[.]wav/\1' | sort | uniq
many thanks again. I have posted the final code for anybody else down below, I ran an echo as you suggested and it seems to be good. I will run the script tonight.
#!/bin/bash
ls | sed -e 's/.*\([0-9]\{8,8\}\).*[.]wav/\1/' | sort | uniq | while read LINE
do
echo tar czf ${REPLY}.tar.gz *${REPLY}*
done
Last edited by yoshima; 09-28-2007 at 05:13 AM.
Reason: Spelling mistake
Distribution: approximately NixOS (http://nixos.org)
Posts: 1,900
Rep:
Hm, I would not call this a final script. You can throw away 'LINE' after read - it will still store result in $REPLY. Also you'd better accumulate output somewhere and chmod a+x it - you'll need to run it..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.