Append timestamp create .trg file for all content of an unzipped archive

Hi,
I have a test.zip archive that contains
test.zip --> (file_1.txt, file_2.txt , file_3.txt)

I need to unzip the file like this,

file_1_timestamp.txt
file_1_timestamp.trg
file_2_timestamp.txt
file_2_timestamp.trg
file_3_timestamp.txt
file_3_timestamp.trg

Could you please let me know that, How to do this job through shell script (ksh).
Thanks in advance

You mean the current timestamp?

Something like this?

unzip test.zip
cd test
rename "s/\./_$(date +%H%M%S)\./" *

--ahamed

Thanks Ahamed,
I have to do this as a postprocessing script after receiving the zip archive,
I can't rename all contents of the directory because of it's a shared directory

1- unzip file.zip 
2- for each file in zip archive "append filename+ current timestamp"
3- for each file created in last step create a copy/touch with trg file extention "filename+ current timestamp.trg"
4- results will be in a shared directory

what do you think?

Try this...

This will rename all the files inside the test directory which will get created once you unzip the file with the current time stamp.
Then it will create a copy of each file with the extenstion .trg
Once done, you can move all the files to the shared folder or wherever you want.

unzip test.zip
cd test
rename "s/\./_$(date +%H%M%S)\./" *
ls | xargs  -l sh -c 'cp $0 ${0%.*}.trg'

--ahamed

unfortunately on my box i found util versione of "rename", so i found this code;

for file in *.zip
  do
      mv $file ${file}`date +%Y%m%d'
  done

ls | xargs  -l sh -c 'cp $0 ${0%.*}.trg'

but if my process launchs two instance of script after of reception of two seperate .zip archive, under my work dir i will have two set of file, how can i determine which file belongs to first script invocation and which group belongs to second instance of script, any idea, thanks anyway Ahamad

'mv' with a destination inside the same folder should be atomic. Only one will end up renaming the file, the other will harmlessly say 'no such file or directory'.

I am confused on what you want now.

The following code when run from the directory where the zip files exists will

For all the zip files

  1. unzip the file
  2. cd to the unzipped folder
  3. rename the file with timestamp
  4. create a copy of the renamed file with the extension .trg
for file in *.zip; do
  unzip $file
  cd ${file%.*}
  for fl in *; do
    ext=${fl##*.}
    new_fl=${fl/.*/}_$(date +%Y%m%d)$ext
    mv $fl $new_fl
    cp $new_fl ${new_fl/.*/.trg}
  done
  cd ../
done

Untested, should work.

--ahamed

You can mount the zip and work as if normal files, too.