[Solved] Help -file archival


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers [Solved] Help -file archival
# 1  
Old 02-05-2014
Question [Solved] Help -file archival

Hi All,
I have a scenario to append all the CSV files with date while moving from one directory to another directory .

e.g.
Source DIR - A

files (can be more files, not sure about file names , but csv format )
Code:
a.csv,
bc.csv,
el.csv,...

Target Dir - B

I want my file names as
Code:
a$date.csv,
bc$date.csv,
el.$date.csv,...

Where $date- today's date

Last edited by bartus11; 02-05-2014 at 04:23 PM.. Reason: Please use [code][/code] tags.
# 2  
Old 02-05-2014
Code:
DT=$( date +"%Y%m%d" )

for file in DIR_A/*.csv
do
        fname="${file##*/}"
        echo mv "$file" "DIR_B/${fname%.csv}${DT}.csv"
done

Remove echo if output looks good. Replace DIR_A, DIR_B with actual absolute paths.
This User Gave Thanks to Yoda For This Post:
# 3  
Old 02-05-2014
a sample script below will go through all csv files in the current directory and rename files with current date:
Code:
#!/bin/ksh
today=$(date '+%Y%m%d');
for fname in *.csv; do
        new_name=${fname%.csv}${today}.csv;
        echo $fname $new_name;
        # mv $fname $new_name;
done

here are csv files in my directory:
Code:
$ ls *csv
aaa.csv
bbb.csv

and here is result:
Code:
aaa.csv aaa.20140205.csv
bbb.csv bbb.20140205.csv

if you see that results fit you then uncomment the mv statement below echo and it will do the job.

If you want to place resulting files in another directory just add the archival directory to the script
Code:
ARCH_DIR=/my/arch/folder;

and change the new_name forming to reflect that:
Code:
new_name=${ARCH_DIR)/${fname%.csv}.${today}.csv;

This User Gave Thanks to migurus For This Post:
# 4  
Old 02-05-2014
One nice archiving method is to zip the files and directories. HXTT JDBC can read them from zip like a table, selecting zip files and zipped files by wild card to form a table. The shrink great, too, and might come out faster, as CPUs are way faster than disks.
# 5  
Old 02-06-2014
Hi All ,
Thanks For your reply .

Now if i have multiple file with different extn
Code:
[a.txt
b.csv
e.xml]

How to i see the output as
Code:
[a$DT.txt
b$DT.csv
e$DT.xml]


Last edited by AspiringD; 02-06-2014 at 01:21 PM..
# 6  
Old 02-06-2014
Code:
for file in *.txt *.csv *.xml

# 7  
Old 02-06-2014
Hi Yoda , the file can be of any extension
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] File reformat

I am using the code below to reformat the input (hp.txt). The output (newhp.txt) is not in the desired format and I can not seem to figure it out. I have attached both. Thank you. perl -aF/\\t/ -lne 'print join(" ",@F) for ("0 A","0 G","0 C","0 T","A 0","G 0","C 0","T 0")' hp.txt > newhp.txt ... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. UNIX for Dummies Questions & Answers

[Solved] Assign file name = to string in a different file

I have two files: pgmname.ou1 - contains invoice data pgmname.ou2 - contains unique file name for pgmname.ou1 I want to copy pgmname.ou1 to a file with the name specified in pgmname.ou2. So if pgmname.ou2 has a line in it with the following data: FILE.NAME.UNIQUE.csv I want to: cpy... (2 Replies)
Discussion started by: rjjv0208
2 Replies

3. Shell Programming and Scripting

[solved] File type error (not a regular file)

Hi friend, i have written script as below to check the file existance. but i got error path="/k/p1100/users/jewel/Output" FILENAME=`ls -lrt $path/*HT|tail -1|cut -d "/" -f 8` if ; then echo "$FILENAME is available " chmod 755 $path/$FILENAME /usr/bin/scp... (0 Replies)
Discussion started by: Jewel
0 Replies

4. UNIX for Dummies Questions & Answers

[Solved] New Line in file

Hi, Though I was successful in following query, I like to know the other ways of doing it. I have a file that is sent as an attachment via mail. However, while opening it, notepad does not recognize new line character whereas other editors like text pad recognizes new line character of unix.... (2 Replies)
Discussion started by: bobbygsk
2 Replies

5. Programming

[Solved] Removing duplicates from the file and saving as new file

Dear All I have 200 data files and each files has many duplicates. I am looking for the automated awk script such that it checks and removes the duplicates from the each file and saving them as new files for all 200 files in the respective folder. For example my data looks like this.. ... (12 Replies)
Discussion started by: bala06
12 Replies

6. Shell Programming and Scripting

[Solved] Need help formatting a file

I have a report similar to the below: ^L"0.1","Run Date : 19/11/10 Navneet Bank, N.A. PAGE NO : 1" "0.2",Proc Date : 19/11/10 GLOBAL A/C SYSTEM ... (2 Replies)
Discussion started by: Gangadhar Reddy
2 Replies

7. Shell Programming and Scripting

small error in shellscripting -archival part

Hi All, I have run the below script but getting one small error. please help me to solve this. ERROR: tar: Error exit delayed from previous errors CODE: #! /bin/bash CEP=/home/user01/exercise/CEP ARCH=/home/user01/exercise/archive LOG=/home/user01/exercise/logs... (3 Replies)
Discussion started by: aish11
3 Replies

8. Shell Programming and Scripting

[solved] merging two files and writing to another file- solved

i have two files as file1: 1 2 3 file2: a b c and the output should be: file3: 1~a 2~b 3~c (1 Reply)
Discussion started by: mlpathir
1 Replies

9. UNIX for Dummies Questions & Answers

Archival Tool for UNIX

Hi All, Need to get the information if there is any tool on Unix for Archiving and retrival of documents automatically. Having the capbalilty to integrate with other systems. And provide the APIs which can be called from other Systems to facilitate automatic Archival and Retrieval. Thanks &... (7 Replies)
Discussion started by: sanjeev0915
7 Replies
Login or Register to Ask a Question