Linux Shell Programming: Pocket Primer by Oswald Campesato

Linux Shell Programming: Pocket Primer by Oswald Campesato

Author:Oswald Campesato
Language: eng
Format: epub
Publisher: Mercury Learning and Information


Searching zip Files for a String

There are at least three ways to search for a string in one or more zip files. As an example, suppose that you want to determine which zip files contain SVG documents.

The first way is shown here:

for f in `ls *zip` do echo "Searching $f" jar tvf $f |grep "svg$" done

When there are many zip files in a directory, the output of the preceding loop can be verbose, in which case you need to scroll backward and probably copy/paste the names of the files that actually contain SVG documents into a separate file. A better solution is to put the preceding loop in a shell and redirect its output. For instance, create the file findsvg.sh whose contents are the preceding loop, and then invoke this command:

./findsvg.sh 1>1 2>2

Notice that the preceding command redirects error message (2>) to the file 2 and the results of the jar/grep command (1>) to the file 1.



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.