The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Advanced & Expert Users
Google UNIX.COM


UNIX for Advanced & Expert Users Advanced UNIX and Linux questions go here. Expert-to-Expert.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to search for text within compressed file HLee1981 UNIX for Advanced & Expert Users 8 09-06-2007 03:50 AM
Line count for compressed files swamy455 Shell Programming and Scripting 1 08-02-2007 07:40 PM
Search in a file and get the next line as well turi UNIX for Dummies Questions & Answers 2 07-02-2007 02:20 PM
search and retrieve previous line in file paulsew Shell Programming and Scripting 2 02-23-2007 04:04 AM
In Line File Modifications: Search and Replace Shakey21 Shell Programming and Scripting 2 11-20-2001 12:21 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-05-2007
Registered User
 

Join Date: Aug 2007
Posts: 2
Search first line of compressed file

I want to read a directory full of compressed files and move the file to another directory if it meets certain criteria. I only want to look at the first line of the compressed file and if I find the string, do the move. I am currently using the following:

zgrep -R -L IH120070731/psoft/bnydata/etl/BNY_CRDW_UAT/source_archive/08012007 | xargs -i {} mv {} ../20070731/{}

This does fine and doesn't run too bad if most of the files will be moved. It takes forever for the zgrep to go through every line of every file when I really only want to check the first line.

Any ideas on how to limit the search to the first line only?

Thanks in advance.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 09-05-2007
Registered User
 

Join Date: Jan 2007
Posts: 16
instead of using a zgrep ...try using a zcat as below
DIRECTORY=<Location where the files are located>
NEWDIR=<Desination folder>
for file in `ls -1 $DIRECTORY/*.Z`
do
LC=`zcat $file |head -1|grep "${STRING}"|wc -l`
if test $LC -eq 1
then
mv $file $NEWDIR/.
fi
done
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:26 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0