Linux - NewbieThis 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!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
NAME
unzip - list, test and extract compressed files in a ZIP archive
SYNOPSIS
unzip [-Z] [-cflptTuvz[abjnoqsCDKLMUVWX$/:^]] file[.zip] [file(s) ...] [-x xfile(s) ...]
[-d exdir]
What you should take from the man page is that "unzip" does not unzip multiple zips in one command. It does one, and any other unswitched arguments are the files to extract out of the zip.
Here's a loop to get you started:
Code:
for i in $(ls); do
cd $i;
unzip Output.zip;
cd ..;
done
Hi, thanks again for putting so much effort in my case. I first have to understand the difference between bash and sh , then ill try out your sophisticated version.
Based on Firerat's script, i did the following:
Code:
#!/bin/bash
for i in $(ls); do
cd $i;
basename $i;
grep -c "^>" output.1.clstr;
cd ..;
done
It works out the way i wanted, but i do want to export the complete output into a textfile. Is that possible?
has the $(ls) which is just pointless , and 'dangerous' in a script as it will wordsplit whitespace
Anyway,,, let us ignore that ...
Code:
#!/bin/bash
LogFile=${PWD}/MyLog
InterestedIn="output.1.clstr"
for i in "*/*.zip";do
pushd "${i%/*}"
unzip "${i/*\/}"
LineCount=$(grep -c "^>" "$InterestedIn")
LastLine="$(tail -n1 "$InterestedIn")"
printf "%s\n" "Dir ${i/*\/} No. of Lines : $LineCount : last line : $LastLine" >> "${LogFile}"
popd
done
had trouble figuring out exactly what you want
and your filesnames changed ( output / file1 )
Oh, above is untested.
and personally I would be tempted to only extract the interesting file to a temp dir , work with it and then remove.
but I don’t really know what you want out of the whole process
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.