AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.

 View Only
  • 1.  Need similar tool of zgrep in aix server

    Posted 2 days ago

    On many systems, there is a tool called zgrep which is used to grep content from compressed files. Is there any similar tool available on AIX? My purpose is to grep a particular word from multiple compressed files and display the filenames that contain that word on an AIX server. Could you suggest the best RPM package or another command to solve this issue?



    ------------------------------
    Vivek M
    ------------------------------


  • 2.  RE: Need similar tool of zgrep in aix server

    Posted 2 days ago

    Try gzip -dc [FILE] | grep -i [STRING]

    Doubt you will need to install anything.



    ------------------------------
    Alexander Pettitt
    ------------------------------



  • 3.  RE: Need similar tool of zgrep in aix server

    Posted 2 days ago

    Hi Alexander,
    I have already installed the gzip package and tried this command:
    gzip -dc [FILE] | grep -i [STRING]
    This command is useful to grep the word from all compressed files only, but my query is different. I want to grep and display the file names that contain the word from all compressed files.



    ------------------------------
    Vivek M
    ------------------------------



  • 4.  RE: Need similar tool of zgrep in aix server

    Posted 2 days ago

    Vivek

    zgrep
    should be available through gzip

    AIX Open Source: Where is zgrep?



    ------------------------------
    Hector Speight
    ------------------------------



  • 5.  RE: Need similar tool of zgrep in aix server

    Posted 2 days ago

    I am near allergic to installing anything so I would do something like

    for FILE in $(ls *.gz) ; do
        gzip -dc ${FILE} | grep -ci [STRING] >/dev/null
        if [[ $? -eq 0 ]] ; then
            echo ${FILE}
        fi
    done

    if you do it the other way I would make sure that you explicitly test the "zgrep" exists on the system in your script.

    Going to save this to my interview questions list.



    ------------------------------
    Alexander Pettitt
    ------------------------------



  • 6.  RE: Need similar tool of zgrep in aix server

    Posted 2 days ago

    Hi,

    Thanks for sharing the script. I would like to inform you that zgrep is now working fine on my AIX systems. As I mentioned earlier, I installed the gzip package, and initially, I ran the command using the full path. To simplify the task, I exported the path permanently, and after that, the command started working fine.

    I used the following command to grep the files: # zgrep -il 'string' *.gz



    ------------------------------
    Vivek M
    ------------------------------



  • 7.  RE: Need similar tool of zgrep in aix server

    Posted 18 hours ago

    Hello,

    for FILE in $(ls *.gz) ; do
        gzip -dc ${FILE} | grep -ci [STRING] >/dev/null
        if [[ $? -eq 0 ]] ; then
            echo ${FILE}
        fi

    done

    is the shell glob option disabled or why the $(ls *) construct? What if the filename containes spaces? grep also knows the -q option.  This would be then in ksh93:

    for FILE in *.gz  ; do gzip -dc "$FILE"  | grep -q <string> && print "$FILE" ; done

    Best regards



    ------------------------------
    Plamen Tanovski
    ------------------------------