Here is what I am doing: I want to find which zip files includes this number with number itself for example i want the result be like this :

7505857289 AIRCDR

where the number is my search result and AIRCDRis zipfilename that contains this number among 100000 files

  • Actually, probably grep — list file name where match is found will be more suitable – Sergiy Kolodyazhnyy Jun 26 '18 at 5:48
  • Basically, just do grep -rH '7505857289' <directory_name>. -r is for recursive search down directory tree, and -H to include filename. If you run into Argument list too long error, use find -type f -exec grep -H '7505857289' {} \; – Sergiy Kolodyazhnyy Jun 26 '18 at 5:51
  • @SergiyKolodyazhnyy thanks for your comment but not sure if my question wasn't clear or you didnt get it i said i have i +1000000 of CDR zip files i want to find 7505857289 with file names that contain that number as u said grep -rH '7505857289' is working but not here............................ this is example of my files AIRCDR9876_20180605-232341.AIR_6567.gz AIRCDR9877_20180605-232842.AIR_6568.gz AIRCDR9878_20180605-233343.AIR_6569.gz and here is command which didnt work: gunzip -c AIRCDR9* |strings|grep -rH '7505857289' – Ali XTAR Jun 26 '18 at 6:48
  • @AliCisco Alright, your original post didn't mention zip files, so it was indeed unclear and when you say file it just means regular file. The information you posted in the comment just now should be inside the question itself, so please edit that so that others can see it. – Sergiy Kolodyazhnyy Jun 26 '18 at 6:54
  • See if this one helps: askubuntu.com/q/971701/295286 – Sergiy Kolodyazhnyy Jun 26 '18 at 6:55

According to your comment the “haystack” of your search is a set of gzipped text files (based on the file name extension .gz). You can scan them with the zgrep command, a wrapper around the grep command that decompresses gzipped files on the fly and supports most of the same options as grep itself.

Thus you can simply run

zgrep -oHe 7505857289 <FILES>...

which will print the name of the source file followed by a colon and the matching character sequence for each match.

If you need a specific output format I recommend that you transform it. For matching text followed by a space and the source file name that would be:

zgrep ... | sed -re 's/^([^:]*):(.*)$/\2 \1/'

Not the answer you're looking for? Browse other questions tagged or ask your own question.