moving files according to a fixed pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting moving files according to a fixed pattern
# 1  
Old 12-16-2008
moving files according to a fixed pattern

I have a static csv file containing two columns (reporttype as 1st column and reportname as 2nd) as follows:
Transaction,TRN_alltransactions
Transaction,TRN_alltransactions1
Master,MST_allmasters
Master,MST_allmasters1
.
.
.
and so on

I am running a script to ftp all the report files from a remote server to a folder on my local linux machine. The report files are named in the following format
RemoteMachineName_reportNameYYYYMMDD.csv / RemoteMachineName_reportNameYYYYMMDD.csv.zip
e.g. PRDSRV1_TRN_alltransactions20081215.csv / PRDSRV1_MST_allmasters20081215.csv.zip

Now on a daily basis I want to create a directory by the date i.e. yyyymmdd and a subfolder of reporttype under that and move respective report files in appropriate folders

Requirement:
Create folders as:
20081215/Transaction
20081215/Master

Move files PRDSRV1_TRN_alltransactions20081215.csv to folder 20081215/Transaction

Move files PRDSRV1_MST_allmasters20081215.csv.zip to folder 20081215/Master

and so on

How do i achieve this using the static csv and the report files that i download?
# 2  
Old 12-29-2008
Use the date program to generate yourself a custom-formatted date:
Code:
filedate=`date +%Y%m%d`
echo $newname
mkdir -p $filedate/Transaction $filedate/Master

Now with BASH or KSH or ZSH use the {%} splicing function to chop off your filenames' extensions, insert the date variable, and then reapply the extensions:
Code:
mv $TransactionReport $filedate/Transaction/${TransactionReport%.csv}${filedate}.csv
mv $AllMastersReport $filedate/Master/${AllMastersReport%.csv.zip}${filedate}.csv.zip

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Joining fixed width files

Hi All, I need to join fixed width files on a column which is position 1 to 3 and need to have all the records from file1 file1.txt Cu1nullL1L2 Cu2nullL1L2 Cu3nullL1L2 file2.txt Cu1B1B2 Cu3B1B2 output.txt Cu1L1B1L2B2 Cu2L1L2 Cu3L1B1L2B3 I tried but not getting the expected... (12 Replies)
Discussion started by: shash
12 Replies

2. Shell Programming and Scripting

Adding delimiter to a fixed pattern of date

I have a text file as below: jan16201413:17PM jan1620143:17PM jan1620143:17PM jan1620143:17PM jan1620143:17PM I want to add a delimeter which will be space to the date part as below: jan 16 2014 13:17 PM jan 16 2014 3:17 PM jan 16 2014 3:17 PM jan 16 2014 3:17 PM jan 16... (13 Replies)
Discussion started by: Sharma331
13 Replies

3. Shell Programming and Scripting

Moving line above possible? after pattern match?

Team, would like to know if it is possibe to move line above.after TEST pattern match #cat file1 data1 data2 ok Test data1 ok Test data2 Test Output: Test (8 Replies)
Discussion started by: kenshinhimura
8 Replies

4. Shell Programming and Scripting

Sed: how to merge two lines moving matched pattern to end of previous line

hello everyone, im new here, and also programming with awk, sed and grep commands on linux. In my text i have many lines with this config: 1 1 4 3 1 1 2 5 2 2 1 1 1 3 1 2 1 3 1 1 1 2 2 2 5 2 4 1 3 2 1 1 4 1 2 1 1 1 3 2 1 1 5 4 1 3 1 1... (3 Replies)
Discussion started by: satir
3 Replies

5. Shell Programming and Scripting

Moving old files based on pattern

Hi all I am trying to loop through a directory of files using a given search pattern. some of the files will be duplicated due to the pattern, but of the duplicate files i wanted to move the older files to another location. Is there any straightforward way of doing this ? One of ways I... (1 Reply)
Discussion started by: sthapa
1 Replies

6. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

7. UNIX for Advanced & Expert Users

Moving multiple files based on the pattern

I want to search for a particular file name patterns and move them to a specific folder, is it possible to do it with awk or sed? (1 Reply)
Discussion started by: rudoraj
1 Replies

8. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

9. Shell Programming and Scripting

Find required files by pattern in xml files and the change the pattern on Linux

Hello, I need to find all *.xml files that matched by pattern on Linux. I need to have written the file name on the screen and then change the pattern in the file just was found. For instance. I can start the script with arguments for keyword and for value, i.e script.sh keyword... (1 Reply)
Discussion started by: yart
1 Replies

10. Shell Programming and Scripting

Awk with fixed length files

Hi Unix Champs, I want to awk on a fixed length file. Instead if the file was a delimited file, then I could have used -F and then could have easily done manipulation on the fields. How do i do the same in case of fixed length file? Thanks in Advance. Regards. (7 Replies)
Discussion started by: c2b2
7 Replies
Login or Register to Ask a Question