Sponsored Content
Top Forums Shell Programming and Scripting Is better way copy list of multiple files, rename and gzip Post 302933965 by sea on Tuesday 3rd of February 2015 12:20:31 PM
Old 02-03-2015
This works for me localy:

Code:
#!/bin/bash
WORK_DIR="." #"$1"
CONTROL_FILE=controlfile #"$2"
ORIGINAL_DATE=2014.06.13 #"$3"
TARGET_DATE=2015.02.03 #"$4"
declare -i C	# Counter

cd "$WORK_DIR"
C=1

grep Original_File[_-] "$CONTROL_FILE" | \
	while read id entry ; do
		newFile=$(grep New_File[_-]${C} "$CONTROL_FILE"|awk '{print $2}')
		C=$(( $C + 1 ))
		
		# Change to false if there are no STRINGS OLD_DATE or NEW_DATE in the CONTROL_FILE.
		if [ true ]
		then	entry="${entry/\{OLD_DATE\}/$ORIGINAL_DATE}"
			newFile="${newFile/\{NEW_DATE\}/$TARGET_DATE}"
		fi
		
		echo cp "${entry}" "${newFile}"
		echo pkzip -add "${newFile/txt/zip}" "$entry"
		echo
	done

exit 0

Outputs as:
Code:
$ sh dotran-sea

cp AB_P_Cdf_2014.06.13.txt test1_sd_WW_2015.02.03.txt
pkzip -add test1_sd_WW_2015.02.03.zip AB_P_Cdf_2014.06.13.txt

cp DD_P_DAdf_2014.06.13.txt test2vd_WW_new_2015.02.03.txt
pkzip -add test2vd_WW_new_2015.02.03.zip DD_P_DAdf_2014.06.13.txt

cp dsf_P_DEMO_2014.06.13.txt test3cfd_dfP_dff_2015.02.03.txt
pkzip -add test3cfd_dfP_dff_2015.02.03.zip dsf_P_DEMO_2014.06.13.txt

cp sdfd_P_Pd_2014.06.13.txt test4gdd_WW_P_OdfsDUCT_2015.02.03.txt
pkzip -add test4gdd_WW_P_OdfsDUCT_2015.02.03.zip sdfd_P_Pd_2014.06.13.txt

Hope this helps

Last edited by sea; 02-03-2015 at 01:28 PM..
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

gzip, multiple files

Hello Everyone, Here is what I am trying to do. I have four text files, I want to gzip them under unix and mail the zipped file via outlook. I am able to do this easily enough, but using winzip or pkunzip to unzip the file, there is only one file. (In essence, all four files were... (2 Replies)
Discussion started by: smbodnar
2 Replies

2. UNIX for Dummies Questions & Answers

copy and rename list of files

Hi all, I am a newbie in writng unix..I am using ksh shell..Does anyone know how to copy a list o files from directory A to directory B with differnt names? i.e in Dir A, I have RPT101.555.TXT RPT102.666.TXT and I want to copy those files to dir B with new naming convention.. in Dir B,... (7 Replies)
Discussion started by: kinmak
7 Replies

3. UNIX for Dummies Questions & Answers

script to rename files with current date and copy it.

I have few webservers logs like access.log. which would be growing everyday. what i do everyday is, take the backup of access.log as access.log_(currentdate) and nullify the access.log. So thought of writing a script... but stuck up in middle. My requirement: to take the backup and nullify... (6 Replies)
Discussion started by: logic0
6 Replies

4. Shell Programming and Scripting

Copy files from folder and rename them

hello, I need to build a shell script that receives the folder to copy by parameter and copy all files except thumb.db to another folder and rename them like, file.jpg renamed to file_bb1.jpg. can someone help me Thanks (4 Replies)
Discussion started by: zeker
4 Replies

5. Shell Programming and Scripting

Files rename and copy

hello, I am write a Script and i would listing all Files from Path1 out with DSR*.txt and give a new name an copy to the Path2. I have problems with that to rename. Someone can help me? Sorry, for my english. My english is not gut. I hope you understand my. That is my Script. ... (2 Replies)
Discussion started by: efeijoo
2 Replies

6. Shell Programming and Scripting

Help with script to copy/rename files, then delete by date

Hi All, I am new to scripting and am looking for some assistance setting up a script. Basically I need the script to scan a folder for the newest files and make a copy of those files, adding a month to the date stamp. I also need this script to delete the previously copied files to save space.... (4 Replies)
Discussion started by: Lucid13
4 Replies

7. Shell Programming and Scripting

Linux Script to copy and rename files through SQL statement

Hi, I require help to complete below requirement through Linux Script. I have a SQL query which shows two columns as output. One is Report Name and other is report path. Query return multiple rows. below is the output. Report Name Cotton Stock Report (Net Weight)- Customized Output... (3 Replies)
Discussion started by: usman_oracle
3 Replies

8. Shell Programming and Scripting

Oop to copy and rename files through SQL Statement in shell Script

#!/bin/sh sqlplus -s "/ as sysdba" << EOF SET HEADING OFF SET FEEDBACK OFF Select pt.user_concurrent_program_name , OUTFILE_NAME FROm apps.fnd_concurrent_programs_tl pt, apps.fnd_concurrent_requests f where pt.concurrent_program_id = f.concurrent_program_id and pt.application_id =... (1 Reply)
Discussion started by: usman_oracle
1 Replies

9. UNIX for Beginners Questions & Answers

Compress multiple gzip files

Good afternoon friends. I wanted to make a query, how to compress several files and leave them all in 1, for example flat text files: filename_1.csv filename_2.csv filename_3.csv expected result filename_end.gzip = (filename_1.csv filename_2.csv filename_3.csv) please (2 Replies)
Discussion started by: tricampeon81
2 Replies
GZFORCE(1)						      General Commands Manual							GZFORCE(1)

NAME
gzforce - force a '.gz' extension on all gzip files SYNOPSIS
gzforce [ name ... ] DESCRIPTION
gzforce forces a .gz extension on all gzip files so that gzip will not compress them twice. This can be useful for files with names trun- cated after a file transfer. On systems with a 14 char limitation on file names, the original name is truncated to make room for the .gz suffix. For example, 12345678901234 is renamed to 12345678901.gz. A file name such as foo.tgz is left intact. SEE ALSO
gzip(1), gznew(1), gzmore(1), gzgrep(1), gzdiff(1), gzexe(1) ATTRIBUTES
See attributes(5) for descriptions of the following attributes: +--------------------+-----------------+ | ATTRIBUTE TYPE | ATTRIBUTE VALUE | +--------------------+-----------------+ |Availability | SUNWgzip | +--------------------+-----------------+ |Interface Stability | External | +--------------------+-----------------+ NOTES
Source for gzip is available in the SUNWgzipS package. GZFORCE(1)
All times are GMT -4. The time now is 02:08 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy