![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| how do i pattern match a field with awk? | someone123 | Shell Programming and Scripting | 4 | 06-03-2008 05:08 AM |
| how to use pattern match with grep | rei | UNIX for Dummies Questions & Answers | 5 | 01-05-2007 01:33 AM |
| Match portion of the filename | mpang_ | Shell Programming and Scripting | 1 | 06-27-2006 03:20 AM |
| pattern match and substitution, can you help? | frustrated1 | Shell Programming and Scripting | 4 | 02-20-2006 05:48 AM |
| How to pattern match on digits and then increment? | sdutto01 | Shell Programming and Scripting | 2 | 08-11-2005 11:46 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
To identify filename in which having match PATTERN
Hi,
Any idea to identify bunch of files( gz format) in which having match PATTERN wanted and print out those files ? Regards, |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
write a script that gunzip the files, grep for pattern and notice you if pattern is found.
|
|
#3
|
||||
|
||||
|
If you are meaning of individual .gz files, you can use zgrep
Code:
$ cat abc.txt unix a unix $ gzip.exe abc.txt $ zgrep "unix" abc.txt.gz unix unix |
|
#4
|
||||
|
||||
|
zgrep is not on every system... on my linux (ubuntu) server: yes. on my solaris nevada: no.
so, the answer depends on your os |
|
#5
|
|||
|
|||
|
If there is a single file, should be easiar. But what if I hv list of 1000 files, in which I want to identify which filelist are contains those matched pattern.
Please advise. |
|
#6
|
||||
|
||||
|
Quote:
Code:
for i in `ls -1 *.gz` do |
|
#7
|
|||
|
|||
|
*bling* Useless Use of Glob in Backticks! Also the "ls -l" actually is a rather grave error. You could simply drop the -l, but the whole ls is redundant.
Code:
for i in *.gz do gzip -dc <$i | fgrep "string" >/dev/null && echo $i done zgrep is actually fairly buggy for stuff like this; other than that, it is the proper answer. It's a fairly small shell script so you could simply find it in Google and copy to your $HOME/bin |
|||
| Google The UNIX and Linux Forums |
| Tags |
| linux, solaris, ubuntu |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|