0

I have some zip files like below.

./etk/test/etf_time_series_am_update.zip
./etk/test/etf_time_series_am_delete.zip
./etk/dir1/etf_time_series_am_update.zip
./etk/dir1/etf_time_series_am_delete.zip
./etk/dir1/dir2/etf_time_series_am_update.zip
./etk/dir1/dir2/etf_time_series_am_delete.zip
./etk/dir1/dir2/dir3/etf_time_series_am_update.zip
./etk/dir1/dir2/dir3/etf_time_series_am_delete.zip

I want these files to unzip and store into the another folder. like

./newf/test/etf_time_series_am_update.txt
./newf/test/etf_time_series_am_delete.txt
./newf/dir1/etf_time_series_am_update.txt
./newf/dir1/etf_time_series_am_delete.txt
./newf/dir1/dir2/etf_time_series_am_update.txt
./newf/dir1/dir2/etf_time_series_am_delete.txt
./newf/dir1/dir2/dir3/etf_time_series_am_update.txt
./newf/dir1/dir2/dir3/etf_time_series_am_delete.txt

I tried with the find command and able to unzip, but couldn't copy in the destination folder.

I tried to unzip by following command. but have no idea about copy into the destination folder.

find -name '*.zip' -exec sh -c 'unzip -d "${1%.*}" "$1"' _ {} \; 
Hara
  • 1,467
  • 4
  • 18
  • 35
ggupta
  • 675
  • 1
  • 10
  • 27
  • could you provide the peace of code you wrote, and what error you are facing, if you could paste error and code, it would helpful to answer question. – Hara May 30 '17 at 09:14
  • this might be asked without down-voting the question @@ – ggupta May 30 '17 at 09:37

1 Answers1

0

This might be works for you.

find . -name "*.zip" | while read filename; do unzip -o -d "`dirname "$filename" | sed -r 's/etk/newf/g'`" "$filename"; done;

You may also get better solution by referring following links.

Hara
  • 1,467
  • 4
  • 18
  • 35
  • only getting unzipped. not able to copy the extracted fields into the folder newf – ggupta May 30 '17 at 11:20
  • @ggupta, sorry, I tried the code, it is working only one level of recursion. this code may need to correct, to do for multiple levels of folder creation. I am new to shell script. I am also trying to find the solution. but if you are ok, instead of one line command, you can go for shell script which can do step by step. – Hara May 30 '17 at 11:43