Archive files to different target folders based on criteria


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Archive files to different target folders based on criteria
# 1  
Old 08-30-2011
Debian Archive files to different target folders based on criteria

Hi All,
I am creting archive script in which i need to split the source file's to different target folder's based on the input file name first character.

Input1.txt -- will contains file names that are needs to be Archive.

Input1.txt
Code:
A1213355
B2255666
C2254555
A6655444
C5566445

Source folder will have many different source files , from the source file i needs to archive only the files which are listed in the Input1.txt
sample source folder files
Code:
A1213355
A6565656
B2255666
B5555555
C2254555
A6655444
C5566445

my desired output is based on input1.txt:
AFolder-- should have archived files [A1213355,A6655444]
BFolder-- should have archived files [B2255666]
CFolder-- should have archived files [C2254555,A6655444,C5566445]

my code is like:
Code:
#!/usr/bin/ksh
CURRDATE=`date +%Y%m%d%H%M%S`
Filest="A:AFolder  B:BFolder C:CFolder"
for a in ${Filest}
do
        FOLDER=`echo ${CURRENT_SET} | cut -f2 -d:`
        FILE_NAME=`echo ${CURRENT_SET} | cut -f1 -d:`
        echo ${FOLDER}
        echo ${FILE_NAME}
done
 
cat $SOURCE_FOLDER/input1.txt |
        while read N
                do
                tar -cvf $FOLDER/$N"_"$CURRDATE.tar $SOURCE_FOLDER/$N
        done

Could you please guide me how to achieve this task...Smilie

Thanks in advance...

Last edited by kmsekhar; 08-30-2011 at 07:58 AM.. Reason: Clear Description
# 2  
Old 08-30-2011
Code:
#!/bin/bash
for i in A B C
do
        dir_list=`ls -d ${i}*`
        tar -cvf ${i}Folder.tar $dir_list >/dev/null
        compress -f ${i}Folder.tar
done

# 3  
Old 08-30-2011
Try:
Code:
find -name '????????' | awk -vinput=Input1.txt '
BEGIN {
  while((getline line < input) > 0) {
    tmp = substr(line, 1, 1) "Folder"
    a[line] = tmp
    system("echo mkdir -p " tmp)
  }
}
$0 in a {system("echo mv -v " $0 " " a[$0])}'

If everything is ok, remove echo-s and add tar-s for directories
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Move multiple files 4rm Source to different target folders based on a series num in the file content

Dear Experts my scenario is as follows... I have one source folder "Source" and 2 target folders "Target_123456" & "Target_789101". I have 2 series of files. 123456 series and 789101 series. Each series has got 3 types of fiels "Debit", "Refund", "Claims". All files are getting... (17 Replies)
Discussion started by: phani333
17 Replies

2. Linux

Merge two files based on matching criteria

Hi, I am trying to merge two csv files based on matching criteria: File description is as below : Key_File : 000|햇|Key_HF|햇|Key_FName 001|햇|Key_11|햇|Sort_Key22|햇|Key_31 002|햇|Key_12|햇|Sort_Key23|햇|Key_32 003|햇|Key_13|햇|Sort_Key24|햇|Key_33 050|햇|Key_15|햇|Sort_Key25|햇|Key_34... (3 Replies)
Discussion started by: PK29
3 Replies

3. Solaris

Move files into different folders based on its month

Hi All, I want to move the files in to different folders based on the files month in the file timestamp. For example All the september files in the directory should moves into the folder "sep_bkp_files" , August files in to aug_bkp_files folder... Please help me to achive the above... (10 Replies)
Discussion started by: velava
10 Replies

4. UNIX for Dummies Questions & Answers

How to fetch files right below based on some matching criteria?

I have a requirement where in i need to select records right below the search criteria qwertykeyboard white 10 20 30 30 40 50 60 70 80 qwertykeyboard black 40 50 60 70 90 100 qwertykeyboard and white are headers separated by a tab. when i execute my script..i would be searching... (4 Replies)
Discussion started by: vinnu10
4 Replies

5. UNIX for Dummies Questions & Answers

How to select files based on a criteria?

I have a file..... xxx 2345 455 abc 345 555 cdf 456 777 fff 555 888 Now my requirement is, Say if, i want to select only those records prior to the record fff 555 888... how do i go about doing this in unix.... The fff would be hardcoded as it wud be fixed and everytime when i... (7 Replies)
Discussion started by: saggiboy10
7 Replies

6. Shell Programming and Scripting

Archive different folders based on their names

This is my first post so ... be gentle:) Hello I have several folders that are backed up daily in following format: /back_YY.MM.DD/backup1/* ........................./backup2/* I looking a script to archive and rename all backup folders bazed on root folder... (8 Replies)
Discussion started by: vilibit
8 Replies

7. Shell Programming and Scripting

Creating folders based on number of files

I have hundreds of files numbered in consecutive number in one single folder What I would like to do is to make as many subfolders as needed (dependeing on the number of individual files) and name them Folder01, Folder02, etc. Then, move file01 to folder01, file02 to folder02 so on and so... (3 Replies)
Discussion started by: Xterra
3 Replies

8. Shell Programming and Scripting

deleting files and folders matching criteria

Hello, I'm spendind hours trying to figure out how a script could remove files and folders older than 30days in a given volume (/dataVolumes/Booba.1.0). Within this volume, all users have their personal folder that starts with "RC-..", so the script should skip them for deletion. I will... (4 Replies)
Discussion started by: H3001
4 Replies

9. UNIX for Dummies Questions & Answers

how to move files into different folders based on filename

I need to move a bunch of files into folders that have the same name. I wanted to either do this with some filter command or some type of batch file that I could save that would already include all of the mv commands since I will have to do this process often. Whatever method you think is easier. ... (7 Replies)
Discussion started by: italia5
7 Replies
Login or Register to Ask a Question