Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-28-2013, 01:08 AM   #1
Registered: Nov 2009
Posts: 43

Rep: Reputation: 15
Required script zip file rename with the contain of file

Dear all,

we need below script.

we have run for loop and unzip and rename same but still require detail not coming.

e.g i have below two file

need to rename file name with 1139 with 1200.

Most important is

inside file all file have below structure

inflating: 1139.20000625162706.disc_pro.iu
inflating: 1139.20000625162706.disc_gq.iu
inflating: 1139.20000625162706.disc_iq.iu
inflating: 1139.20000625162706.disc_iqd.iu
inflating: 1139.20000625162706.disc_rul.iu
inflating: 1139.20000625162706.disc_lin.iu
inflating: 1139.20000625162706.disc_rulld.iu

that also need to rename 1139 to 1200 and that file need to rename with


Script i wrote as below.

for file in *.zip
unzip -l $file | grep -q 1139
cp $file /home/tplinux/tmp/idoc/in
cd /home/tplinux/tmp/idoc/in/
unzip $file
rename "1139." "1200." *.*
ls -ltr | awk '{print $9}' >> 3.txt
ff=`tail -1 3.txt`
echo $ff
rm 3.txt *.zip
ss=`expr substr $ff 1 19`
zip $ff *.*
ls -ltr | grep -v "zip" | awk '{print "rm -rf " $9}' | sh
touch bingo.$ss

Last edited by dhirendrs; 06-28-2013 at 01:27 AM.
Old 06-28-2013, 12:03 PM   #2
David the H.
Bash Guru
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960Reputation: 1960
First of all, please use ***[code][/code]*** tags around your code and data, to preserve the original formatting and to improve readability. Do not use quote tags, bolding, colors, "start/end" lines, or other creative techniques. Thanks.

I'm not completely sure I understand what you need. You want to unzip the contents of the archive, replace a string in each name, then re-zip it?

What is the exact problem you're having with the script you posted? I can't understand half of what it's trying to do. What's all that stuff with awk, 3.txt, expr (a useless command since modern shells have built-ins that can do everything it does), and all that? parsing ls is not recommended in any case, so I doubt it's doing any good.

Couldn't you just do something like this?



[[ -d $tempdir ]] && cd "$tempdir" || { echo 'No tempdir available' ; exit 1 ;}

for zipfile in "$zippath/"*.zip; do

    unzip "$zipfile"

    for fname in *; do
        mv "$fname" "${fname/1139/1200}"


    zip "$outzip" *

    rm -f *


exit 0
Please explain if you need something else.

Last edited by David the H.; 06-28-2013 at 12:05 PM. Reason: minor rewording


shell script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] HowTo: Find a file, rename and copy new file in one script! pietmomberg Linux - Newbie 17 06-02-2013 06:08 AM
Shell script to get name of file, delete original file, rename blank file chrisgti Linux - General 11 09-15-2012 02:49 AM
How to find out a file in a WAR which in a zip without unzip the zip-file? thomas2004ch Linux - Software 3 09-30-2011 03:06 PM
Script to rename a file saghir27 Linux - Newbie 1 04-29-2008 08:20 AM
File rename script jjwl89 Linux - General 1 03-14-2005 06:28 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:23 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration