Python Forum
Search string in mutliple .gz files
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search string in mutliple .gz files
(Aug-25-2021, 08:47 AM)DeaD_EyE Wrote:
(Aug-25-2021, 04:18 AM)ndc85430 Wrote: What's the reason for reimplementing zgrep?

Reimplementing it in Python is better like this:

import subprocess

def zgrep(file, pattern):
    proc = subprocess.Popen(["zgrep", pattern, file], stdout=subprocess.PIPE)
    for line in proc.stdout:
        yield line.decode(errors="replace")
Code, which utilizes zgrep, does not run on Windows.
In addition, it adds a dependency to Python + it's not Python.

The next could be, why to implement cat, sort, awk, sed, ... if we already have them on our machines?
The increase of non-pythonic solutions:

Output: python3 ./ path_to_directory matching_text
Yes, what could this mean?
Have you tried python3 ./ --help

It's the normal way how command line tools are controlled. They take options, arguments and parameters.
If you want to list a directory on Linux, you could type: ls -l /

The -l is an option and the / is an argument and points to the target directory which ls should show.

I have tried with python3 still same output - Can you please provide complete code to execute from my end?

$ python3 ./
python3 ./ path_to_directory matching_text

Possibly Related Threads…
Thread Author Replies Views Last Post
  Replace String in multiple text-files [SOLVED] AlphaInc 5 1,363 Aug-08-2021, 04:59 PM
Last Post: Axel_Erfurt
  fuzzywuzzy search string in text file marfer 9 1,057 Aug-03-2021, 02:41 AM
Last Post: deanhystad
  how search files Ron_Crafter 4 1,089 Apr-17-2021, 11:19 AM
Last Post: Ron_Crafter
  I want to search a variable for a string D90 lostbit 3 1,006 Mar-31-2021, 07:14 PM
Last Post: lostbit
  Merging all file_name.log's files from directory to one and search “PerformanceINFO" sutra 0 662 Dec-09-2020, 05:14 PM
Last Post: sutra
  String search in different excel Kristenl2784 0 774 Jul-20-2020, 02:37 PM
Last Post: Kristenl2784
  Complex word search multiple files Kristenl2784 0 782 Jul-18-2020, 01:22 PM
Last Post: Kristenl2784
  Interactive Menu, String Search? maggotspawn 3 1,169 May-11-2020, 05:25 PM
Last Post: menator01
  Search for files and copy them to different location jayser247 4 1,193 Apr-25-2020, 12:50 AM
Last Post: jayser247
  Replace string in many files in a folder metro17 8 2,119 Oct-16-2019, 06:46 PM
Last Post: ndc85430

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020