Strategy to concatenate and backup files


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Strategy to concatenate and backup files
# 1  
Old 02-07-2009
Strategy to concatenate and backup files

I need to be able to concatenate all the files in a directory into a new filename and a different directory. I want to append the date in YYYYMMDD format to the new filename (ie, newfilename_20090207). The original files will have different filenames so I will need to be able to loop thru each file and concatename to newfilename_20090207.

After I successfully create this newfilename_20090207, I need to delete the original files. After I delete all the original files, the directory should not contain any files so it is ready to receive a new set of files the next day.

Does anyone have any code that does something similar to what I need to do so I have a starting point to write this code. I especially need help to loop thru all the files that might exist in the directory. The number of files can vary from day to day.

Thanks.
Ryan
# 2  
Old 02-07-2009
Do the files need to be processed in any particular order? Will they ever be a very large numbeR? This can do it alphabetically, if the files don't have spaces in their names and don't number in the hundreds:

Code:
FILES=( dir/* )
cat ${FILES[*]} > newfilename_$(date +%Y%m%d) && rm ${FILES[*]}

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Concatenate files and delete source files. Also have to add a comment.

- Concatenate files and delete source files. Also have to add a comment. - I need to concatenate 3 files which have the same characters in the beginning and have to remove those files and add a comment and the end. Example: cat REJ_FILE_ABC.txt REJ_FILE_XYZ.txt REJ_FILE_PQR.txt >... (0 Replies)
Discussion started by: eskay
0 Replies

2. UNIX for Dummies Questions & Answers

Concatenate files

Hi I am trying to learn linux step by step an i am wondering can i use cat command for concatenate files but i want to place context of file1 to a specific position in file2 place of file 2 and not at the end as it dose on default? Thank you. (3 Replies)
Discussion started by: iliya24
3 Replies

3. UNIX for Dummies Questions & Answers

Concatenate Several Files to One

Hi All, Need your help. I will need to concatenate around 100 files but each end of the file I will need to insert my name DIRT1228 on each of the file and before the next file is added and arrived with just one file for all the 100files. Appreciate your time. Dirt (6 Replies)
Discussion started by: dirt1228
6 Replies

4. Shell Programming and Scripting

Concatenate files

I have a file named "file1" which has the following data 10000 20000 30000 And I have a file named "file2" which has the following data ABC DEF XYZ My output should be 10000ABC 20000DEF (3 Replies)
Discussion started by: bobby1015
3 Replies

5. Shell Programming and Scripting

Concatenate files

Hi, I want to create a batch(bash) file to combine 23 files together. These files have the same extension. I want the final file is save to a given folder. Once it is done it will delete the 23 files. Thanks for help. Need script. (6 Replies)
Discussion started by: zhshqzyc
6 Replies

6. Shell Programming and Scripting

Concatenate files

I have directory structure sales_only under which i have multiple directories for each dealer example: ../../../Sales_Only/xxx_Dealer ../../../Sales_Only/yyy_Dealer ../../../Sales_Only/zzz_Dealer Every day i have one file produce under each directory when the process runs. The requirement... (3 Replies)
Discussion started by: mohanmuthu
3 Replies

7. Shell Programming and Scripting

concatenate two files with different No of rows

need a shell which perform following function file 1 ( every time new data comes) 1212 2323 3434 4545 5656 . . . . file 2 (fixed line) update bc_tbl set aix=data , bix=back where cix=U and serial=; now when i execute shell it will concatinate file 1, file 2 & make file 3 as... (3 Replies)
Discussion started by: The_Archer
3 Replies

8. Shell Programming and Scripting

Script to concatenate several files

I need a script to concatenate several files in one step, I have 3 header files say file.S, file.X and file.R, I need to concatenate these 3 header files to data files, say file1.S, file1.R, file1.X so that the header file "file.S" will be concatenated to all data files with .S extentions and so on... (3 Replies)
Discussion started by: docaia
3 Replies

9. UNIX for Dummies Questions & Answers

How to concatenate all files.

Hi, I'm totally new to Unix. I'm an MVS mainframer but ran into a situation where a Unix server I have available will help me. I want to be able to remotely connect to another server using FTP, login and MGET all files from it's root or home directory, logout, then login as a different user and do... (1 Reply)
Discussion started by: s80bob
1 Replies

10. Solaris

What is an Ideal Backup Strategy

Hi, we have a solaris setup in our company and i have been assigned on a project of planning a backup strategy . ours is a midium level company. please help me so that i can plan an Ideal Backup Strategy. Thanks, Una (6 Replies)
Discussion started by: una
6 Replies
Login or Register to Ask a Question