LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 09-27-2007, 02:04 PM   #1
yoshima
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Rep: Reputation: 0
Angry 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.

Any help on this would be greatly appreciated.

 
Old 09-27-2007, 02:26 PM   #2
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
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.
 
Old 09-27-2007, 03:23 PM   #3
yoshima
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Thumbs up

Raskin,

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

Is giving me:

sed: -e expression #1, char 32: Unterminated `s' command

Many thanks again in advance.
 
Old 09-27-2007, 10:40 PM   #4
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
OOps, add / in the end...
ls | sed -e 's/.*\([0-9]\{8,8\}\).*[.]wav/\1/' | sort | uniq

sed arguments:

s/ -replace

.*\([0-9]\{8,8\}\).*[.]wav - expression to replace:
.* - anything
\([0-9]\{8,8\}\) - 8 times [0-9] and remember it
[0-9] - any digit

\1 - replace with, first remembered expression.

sort - I guess obvious; uniq - remove duplicate adjacent lines.
 
Old 09-28-2007, 05:13 AM   #5
yoshima
LQ Newbie
 
Registered: Sep 2007
Posts: 5

Original Poster
Rep: Reputation: 0
Cool Final Code Many Thanks!!!

Raskin,

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
 
Old 09-28-2007, 05:17 AM   #6
raskin
Senior Member
 
Registered: Sep 2005
Location: Russia
Distribution: NixOS (http://nixos.org)
Posts: 1,893

Rep: Reputation: 68
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..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a script for daily backup of oracle archive file sathyguy Linux - Newbie 15 01-22-2007 06:49 AM
Automated FTP script to grab ONLY newest dated files kaiserbeto Linux - Newbie 4 10-20-2006 02:46 AM
shell script - add file to archive ? xconspirisist Linux - Software 2 03-20-2004 03:27 PM
Create an archive file which includes files in sub-directories? amaze Linux - General 1 09-26-2003 08:43 AM
how to create a archive .a file using g++? hari_linux Programming 0 03-07-2003 09:12 AM


All times are GMT -5. The time now is 01:50 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration