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 8 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 8 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 7 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 7 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 7 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 7 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 6 days 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
    ------------------------------



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

    Posted 5 days ago

    As a total fan of one-liners i also have to admit, that this will not do the trick. It misses the grep options like -l, -n or the like.

    We have installed zprep from the AIX-Toolbox (gzip-1.11-1.ppc). I would strongly suggest to get AIX-Toolbox running on your system(s) as it will also provide you heavily missed tools as "readlink", etc. It also will provide file-checksum verification of installed binaries and so forth.

    That beeing said: zgrep in AIX-Toolbox is wrapper written in common shell.

    I'm just a guy with an email address (and yes, working for a company) but could some trustworthy(!) at IBM or so check signature of the attached code before anyone(!) runs it?

    It is under GPL.



    ------------------------------
    Wilhelm Seyerl
    ------------------------------