Search code examples
unixgrepcut

unix: cut with .gz file


I use 'cut' method to grep through some logs:

cut -d'#' -f3-8 logs.txt | grep 'code:1'

Does anybody know how to use it with .gz file?

Any of these doesn't work:

zcut -d'#' -f3-8 logs.gz | zgrep 'code:1'
zcut -d'#' -f3-8 logs.gz | grep 'code:1'
cut -d'#' -f3-8 logs.gz | zgrep 'code:1'

Solution

  • Probably you can use this:

    $ zcat logs.gz | cut -d'#' -f3-8 | grep 'code:1'
    

    The zcat command uncompresses the logs.gz file and writes the uncompressed data on standard output.