There I said it !

  • elmicha@feddit.org
    link
    fedilink
    arrow-up
    25
    ·
    13 days ago

    I agree. zgrep also works for uncompressed files, so we could use e.g. zgrep ^ instead of zcat.

  • allywilson@lemmy.ml
    link
    fedilink
    arrow-up
    17
    ·
    13 days ago

    Yeah, it’s a pain. Leads to bad one liners:

    for i in $(ls); do zcat $i || cat $i; done

      • allywilson@lemmy.ml
        link
        fedilink
        arrow-up
        4
        ·
        12 days ago

        Won’t this cause cat to iterate through all files in the cwd once zcat encounters an issue, instead of just the specific file?

      • gnuhaut@lemmy.ml
        link
        fedilink
        arrow-up
        1
        ·
        edit-2
        11 days ago

        You can just do for f in * (or other shell glob), unless you need find’s fancy search/filtering features.

        The shell glob isn’t just simpler, but also more robust, because it works also when the filename contains a newline; find .. | while read -r will crap out on that. Also apparently you want while IFS= read -r because otherwise read might trim whitespace.

        If you want to avoid that problem with the newline and still use find, you can use find -exec or find -print0 .. | xargs -0, or find -print0 .. | while IFS= read -r -d ''. I think -print0 is not standard POSIX though.

    • interdimensionalmeme@lemmy.mlOP
      link
      fedilink
      arrow-up
      6
      arrow-down
      1
      ·
      edit-2
      13 days ago

      Thanks !

      But still we shouldn’t have to resort to this !

      Also, can’t get the output through pipe

      for i in $(ls); do zcat $i || cat $i; done | grep mysearchterm

      this appears to work

      find . -type f -print0 | xargs -0 -I{} sh -c 'zcat "{}" 2>/dev/null || cat "{}"' | grep "mysearchterm"

      Still, that was a speed bump that I guess everyone dealing with mass compressed log files has to figure out on the fly because zcat can’t read uncompressed files ! argg !!!

      for i in $(ls); do zcat $i 2>/dev/null || cat $i; done | grep mysearchterm

  • Malfeasant@lemm.ee
    link
    fedilink
    arrow-up
    10
    ·
    12 days ago

    How do you propose zcat tell the difference between an uncompressed file and a corrupted compressed file? Or are you saying if it doesn’t recognize it as compressed, just dump the source file regardless? Because that could be annoying.

    • interdimensionalmeme@lemmy.mlOP
      link
      fedilink
      arrow-up
      4
      arrow-down
      2
      ·
      12 days ago

      Even a corrupt compressed files has a very different structure relative to plain text. “file” already has the code to detect exactly which.

      Still, failing on corrupted compression instead of failing on plaintext would be an improvement.

      • Malfeasant@lemm.ee
        link
        fedilink
        arrow-up
        4
        ·
        11 days ago

        What even is plain text anymore? If you mean ASCII, ok, but that leaves out a lot. Should it include a minimal utf-8 detector? Utf-16? The latest goofy encoding? Should zcat duplicate the functionality of file? Generally, unix-like commands do one thing, and do it well, combining multiple functions is frowned upon.

        • interdimensionalmeme@lemmy.mlOP
          link
          fedilink
          arrow-up
          1
          arrow-down
          1
          ·
          10 days ago

          I wouldn’t call all this hoop jumping to reading common log files “doing it better”.

          This is exactly the kind of arcane tinkering that makes everything a tedious time wasting chore on linux.

          At this point it’s accepted that text files get zipped and that should be handled transparently and not be precious about kilobits of logic storage as if we were still stuck on a 80386 with 4 megs of ram.

    • Morphit @feddit.uk
      link
      fedilink
      arrow-up
      2
      ·
      11 days ago
             -f --force
                    If the input data is not in a format recognized by gzip, and if the option --stdout is also given,
                    copy the input data without change to the standard output: let zcat behave as cat.
      

      I don’t know why this isn’t the top comment. I guess there might be some scenario where you’d want to know about non-gzip files where you don’t expect them so changing the defaults would probably cause some subtle breakage. For shell use though, just an alias could be used; alias zcat=gzip -cdf

      • huf [he/him]@hexbear.net
        link
        fedilink
        English
        arrow-up
        1
        ·
        11 days ago

        in that case, i’d prefer a ~/bin/zcat with the contents

        #!/bin/sh
        exec gzip -cdf "$@"
        

        this way, it’s exec’able, unlike an alias or shell function.

  • LemoineFairclough@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    5
    arrow-down
    1
    ·
    12 days ago

    I think that providing an exit status that is not 0 when zcat is used with an uncompressed file is useful. Though my opinion is less strong regarding whether it should write more text after an error occurred, it’s probably more useful for a process to terminate quickly when an error occurred rather than risk a second error occurring and making troubleshooting harder.

    I think that trying to change any existing documented features of widely used utilities will lead to us having less useful software in the future (our time is probably better spent making new programs and new documentation): https://www.jwz.org/doc/worse-is-better.html https://en.wikipedia.org/wiki/Worse_is_better

    • interdimensionalmeme@lemmy.mlOP
      link
      fedilink
      arrow-up
      1
      arrow-down
      1
      ·
      12 days ago

      Not improving existing software leads to stagnation.

      It’s certainly a good part of why so much of linux is an awkward kludgy idiosyncratic mess to use.

      Whatever the first implementation does ends up being a suicide pact by default.

      Another option is to change cat to auto decompress compressed files, instead of printing gibberish.

  • fool@programming.dev
    link
    fedilink
    arrow-up
    4
    ·
    edit-2
    10 days ago

    just use -f lol.

    less $(which zcat) shows us a gzip wrapper. So we look through gzip options and see:

    -f --force
    Force compression or decompression. If the input data is not in a format recognized by gzip, and if the option --stdout is also given, copy the input data without change to the standard output: let zcat behave as cat.

    party music