Sponsored Content
Top Forums Shell Programming and Scripting Is better way copy list of multiple files, rename and gzip Post 302933960 by dotran on Tuesday 3rd of February 2015 11:07:47 AM
Old 02-03-2015
Thanks very much Mr.Don for reply this subject....cause I can't figure what's the best way when use pkzip instead gzip. And out put like below.

Do you mean that you want to use pkzip to create a zip file for each input file using its OLD filename with its filename extension replaced by .zip as the name of the zip file and the contents of that zip file will be the compressed NEW filename? Yes...pkzip one by one and ouput with new name and without extention.txt. Thanks
Code:
/tmp/test: cat controlfile
Original_File_1: AB_P_Cdf_{OLD_DATE}.txt 
Original_File-2: DD_P_DAdf_{OLD_DATE}.txt
Original_File-3: dsf_P_DEMO_{OLD_DATE}.txt
Original_File-4: sdfd_P_Pd_{OLD_DATE}.txt
bla bla until Old_File-100
 
New_File_1: test1_sd_WW_{NEW_DATE}.txt
New_File_2: test2vd_WW_new_{NEW_DATE}.txt
New_File_3: test3cfd_dfP_dff_{NEW_DATE}.txt
New_File_4: test4gdd_WW_P_OdfsDUCT_{NEW_DATE}.txt
bla bla until New_File-100

Code:
 
#!/bin/ksh
TMP_DIR="$1"
CONTROL_FILE="$2"
ORIGINAL_DATE="$3"
TARGET_DATE="$4"
WORK_DIR="$5"
 
#TMP_DIR='/tmp/test'
#WORK_DIR='/staging/test'
 
cd "$TMP_DIR"
/usr/bin/nawk -v TMP_DIR="$1" -v CONTROL_FILE="controlfile" -v ORIGINAL_DATE="$3" -v TARGET_DATE="$4" -v WORK_DIR="$5" '
{       sub(/[{]OLD_DATE[}]/, ORIGINAL_DATE)
}
{       sub(/[{]NEW_DATE[}]/, TARGET_DATE)
}
/^Original_File/ {
        o[++oc] = $2
        next
}
/^New_File/ {
        # Process new file names...
        ++nc    
        printf("cp %s/%s %s\n", WORK_DIR, o[nc], $2)
        #printf("gzip %s\n", $2) 
Something replace with pkzip for each file and output with new name
}' "$WORK_DIR/$CONTROL_FILE" | ksh

Code:
./test.ksh /tmp/test controlfile 20150109 20150230 /staging/test

Code:
 
Example pkzip one by one....
pkzip -add test1_sd_WW_{NEW_DATE}.zip AB_P_Cdf_{OLD_DATE}.txt
pkzip -add test2vd_WW_new_{NEW_DATE}.zip DD_P_DAdf_{OLD_DATE}.txt
pkzip -add test3cfd_dfP_dff_{NEW_DATE}.zip dsf_P_DEMO_{OLD_DATE}.txt
pkzip -add test4gdd_WW_P_OdfsDUCT_{NEW_DATE}.zip sdfd_P_Pd_{OLD_DATE}.txt
bla bla until New_File-100 or 200 files

Output:
Code:
test1_sd_WW_{NEW_DATE}.zip
test2vd_WW_new_{NEW_DATE}.zip
test3cfd_dfP_dff_{NEW_DATE}.zip
test4gdd_WW_P_OdfsDUCT_{NEW_DATE}.zip
bla bla until New_File-100


Last edited by dotran; 02-03-2015 at 12:27 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
ARK(1)								 KDE User's Manual							    ARK(1)

NAME
ark - KDE archiving tool SYNOPSIS
ark [-b] [-a] [-e] [-c] [-f suffix] [-p] [-t file] [-d] [-o directory] [KDE Generic Options] [Qt(TM) Generic Options] DESCRIPTION
Ark is a program for managing various compressed file formats within KDE. Archives can be viewed, extracted, created and modified with Ark. The program can handle various formats such as tar, gzip, bzip2, zip, rar (when the appropriate libraries or command-line programs are installed). OPERATION MODES
Ark can be used either as a stand-alone GUI program as well as a command-line program in order to perform some specific tasks. If invoked without the -b (--batch) or -c (--add) options, Ark is started as a normal GUI program. When the -b (--batch) option is used, Ark can be used to extract the contents of one or more files directly from the command-line, without launching its GUI. When the -c (--add) option is used, Ark prompts for files that should be added to a new archive or to an existing archive. OPTIONS
-d, --dialog Show a dialog for specifying the options for a batch or add operation. -o, --destination directory Default the extraction directory to directory. If not passed, the current path is used. Options for adding files -c, --add Query the user for an archive filename and add specified files to it. Quit when finished. -t, --add-to filename Add the specified files to filename. Create archive if it does not exist. Quit when finished. -p, --changetofirstpath Change the current directory to the first entry and add all other entries relative to this one. -f, --autofilename suffix Automatically choose a filename, with the selected suffix (for example rar, tar.gz, zip or any other supported types). Options for batch extraction b, --batch Use the batch interface instead of the usual dialog. This option is implied if more than one url is specified. -e, --autodestination The destination argument will be set to the path of the first file supplied. -a, --autosubfolder Archive contents will be read, and if detected to not be a single folder archive, a subfolder by the name of the archive will be created. EXAMPLES
ark --batch archive.tar.bz2 Will extract archive.tar.bz2 into the current directory without showing any GUI. ark -b -d archive.tar.bz2 archive2.zip Will first show an extraction options dialog and then extract both archive.tar.bz2 and archive2.zip into the directory chosen in the dialog. ark --add-to my-archive.zip photo1.jpg text.txt Will create my-archive.zip if does not exist and then add photo1.jpg and text.txt to it. AUTHORS
Ark is currently maintained by Harald Hvaal haraldhv@stud.ntnu.no and Raphael Kubo da Costa kubito@gmail.com. This man page was first written by Lauri Watts lauri@kde.org in 2005 for KDE 3.4, and was later updated in 2009 by Raphael Kubo da Costa kubito@gmail.com. AUTHORS
Lauri Watts <lauri@kde.org> Author. Raphael Kubo da Costa <kubito@gmail.com> Author. K Desktop Environment 2.13 (KD 2009-09-10 ARK(1)
All times are GMT -4. The time now is 08:10 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy