Searching a particular string pattern in 10000 files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Searching a particular string pattern in 10000 files
# 1  
Old 08-15-2012
Searching a particular string pattern in 10000 files

Problem Statement:-

I need to search a particular `String Pattern` in around `10000 files` and find the records which contains that `particular pattern`. I can use `grep` here, but it is taking lots of time.

Below is the command I am using to search a `particular string pattern` after `unzipping` the `dat.gz file`

Code:
    gzcat /data/newfolder/real-time-newdata/*_20120809_0_*.gz | grep 'b295ed051380a47a2f65fb75ff0d7aa7^]3^]-1'

If I simply count how many files are there after unzipping the above `dat.gz file`

Code:
gzcat /data/newfolder/real-time-newdata/*_20120809_0_*.gz | wc -l

I get around `10000 files`. And I need to search the above string pattern in all these `10000 files` and find out the records which contains the above `String Pattern`.


What is the best approach on this? Should we take `100 files` at a time and search for the particular String Pattern in that `100 files parallelly`.

Note:

I am running SunOS

Code:
    bash-3.00$ uname -a
    SunOS lvsaishdc3in0001 5.10 Generic_142901-02 i86pc i386 i86pc

# 2  
Old 08-16-2012
Try this perl one-liner and see if it is any better:
Code:
perl -ne 'print if (m/searh_string/)' test*    # Searches all files that begin with: test



---------- Post updated 2012-08-16 at 12:16 AM ---------- Previous update was 2012-08-15 at 10:03 PM ----------

Also try out 'sed' over the unzipped files:
Code:
sed -n '/search_string/p' test*    # Searches all files that begin with: test

# 3  
Old 08-18-2012
Try this one as well:

Code:
find . -name "*_20120809_0_*.gz" -print | xargs zgrep 'b295ed051380a47a2f65fb75ff0d7aa7^]3^]-1'

# 4  
Old 08-20-2012
Quote:
Originally Posted by mjf
Try this one as well:

Code:
find . -name "*_20120809_0_*.gz" -print | xargs zgrep 'b295ed051380a47a2f65fb75ff0d7aa7^]3^]-1'

Just a note, if you have zgrep, you probably have zfgrep which is faster, but doesn't support any kind of regex. But, if you're just looking for a string, go with [z]fgrep
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Searching a pattern in .gz files

in a directory, I have some files(comma seperated) and some .gz files (each .gz file contain one file which again is comma seperated). I want to search and write the names of all those files which contain any particular value (say 1150) at any specified field position(say 10th field). How di I do... (1 Reply)
Discussion started by: Kumar Jivi
1 Replies

2. Shell Programming and Scripting

[SOLVED] Replace a string in nextline after searching a pattern

Hi, I have a requirement where I need to replace a string in a line and this line will be identified by search criteria on previous line: E.g.: I have an xml file and Contents as below: <Root> <NameValue> <name>Global/Text/Data</name> <value>This is valid... (14 Replies)
Discussion started by: mailing2vamsi
14 Replies

3. Shell Programming and Scripting

Searching across multiple files if pattern is available in all files searched

I have a list of pattern in a file, I want each of these pattern been searched from 4 files. I was wondering this can be done in SED / AWK. say my 4 files to be searched are > cat f1 abc/x(12) 1 abc/x 3 cde 2 zzz 3 fdf 4 > cat f2 fdf 4 cde 3 abc 2... (6 Replies)
Discussion started by: novice_man
6 Replies

4. Shell Programming and Scripting

Searching String from set of similar File pattern from the Dir

Guys, Here is the script that searches string from the set of similar files from the log directory, All the file patterns are defined as input file, from where the script should map to those files in the LOG_DIR and should start searching the strings from all those similar files. ... (1 Reply)
Discussion started by: raghunsi
1 Replies

5. Shell Programming and Scripting

Script for searching a pattern in 5 files and deleting the patterns given

Hi All, I have written the below script that searches for the pattern in a file and delete them if present. please can some one have a look and suggest the changes in the script. #!bin/sh # The pattern that user want to add to the files echo "Enter the pattern of the redirect" read... (4 Replies)
Discussion started by: Shazin
4 Replies

6. Shell Programming and Scripting

Searching all files that contain pattern

Hello All, i have to search a pattern in all the files in all subfolders that are present in current directory. suppose i am in d1 directory and in that sd1,sd2,sd3 are subdirectories. in sd1 i have files f1,f2 sd2 i have files f3,f4 sd3 i have file f5 i have to list out all those... (4 Replies)
Discussion started by: ravi.sadani19
4 Replies

7. UNIX for Dummies Questions & Answers

Searching for files with certain string pattern

Hello All I would like to search for files containing certain string pattern under all the directories under /vobs/vobname and print the output to a file in my home directory. How can I do this? Note: /vobs/vobname conatins several directories. Thank You in advance newbetounix (1 Reply)
Discussion started by: intrigue
1 Replies

8. Shell Programming and Scripting

Pattern searching pattern in c files

I have a problem in searching a specific pattern in c files. My requirement: I have to find all the division operator in all cfiles. The problem is, the multi line comments and single line comments will also have forward slash in it. Even after avoiding these comments also, if both... (6 Replies)
Discussion started by: murthybptl
6 Replies

9. Shell Programming and Scripting

Extracting a string from one file and searching the same string in other files

Hi, Need to extract a string from one file and search the same in other files. Ex: I have file1 of hundred lines with no delimiters not even space. I have 3 more files. I should get 1 to 10 characters say substring from each line of file1 and search that string in rest of the files and get... (1 Reply)
Discussion started by: mohancrr
1 Replies

10. UNIX for Dummies Questions & Answers

Pattern searching inside Variable - not looking at files

Hi, I've searched this site and not found this already, so if I missed on my search, sorry. I need to pass in a variable to a script, where the first three characters of that variable represent a calendar quarter, and the last 2 characters are the year. I.E. Q0105 for Q1, Q0205 for Q2, and... (3 Replies)
Discussion started by: Rediranch
3 Replies
Login or Register to Ask a Question