interdimensionalmeme@lemmy.ml to Linux@lemmy.ml · 16 小时前zcat shouldn't error out if you try to zcat an uncompressed file, it should just output the damned file !message-squaremessage-square14fedilinkarrow-up154arrow-down16file-text
arrow-up148arrow-down1message-squarezcat shouldn't error out if you try to zcat an uncompressed file, it should just output the damned file !interdimensionalmeme@lemmy.ml to Linux@lemmy.ml · 16 小时前message-square14fedilinkfile-text
minus-squareallywilson@lemmy.mllinkfedilinkarrow-up12·15 小时前Yeah, it’s a pain. Leads to bad one liners: for i in $(ls); do zcat $i || cat $i; done
minus-squareMonkderVierte@lemmy.mllinkfedilinkarrow-up8·edit-21 小时前Btw, don’t parse ls. Use find |while read -r instead. find -maxdepth 1 -name "term" -print |while read -r file do zcat "$file" 2>/dev/null || cat "$file" done
minus-squareallywilson@lemmy.mllinkfedilinkarrow-up4·4 小时前Won’t this cause cat to iterate through all files in the cwd once zcat encounters an issue, instead of just the specific file?
minus-squareMonkderVierte@lemmy.mllinkfedilinkarrow-up1·1 小时前Yeah, i was tired and had $file there first, then saw that you wanted to cat all in directory. Still tired, but i think this works now.
minus-squareinterdimensionalmeme@lemmy.mlOPlinkfedilinkarrow-up3arrow-down1·edit-215 小时前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
Yeah, it’s a pain. Leads to bad one liners:
for i in $(ls); do zcat $i || cat $i; done
Btw, don’t parse ls. Use
find |while read -r
instead.find -maxdepth 1 -name "term" -print |while read -r file do zcat "$file" 2>/dev/null || cat "$file" done
Won’t this cause cat to iterate through all files in the cwd once zcat encounters an issue, instead of just the specific file?
Yeah, i was tired and had $file there first, then saw that you wanted to cat all in directory. Still tired, but i think this works now.
Thanks !
But still we shouldn’t have to resort to this !
Also, can’t get the output through pipefor i in $(ls); do zcat $i || cat $i; done | grep mysearchterm
this appears to workfind . -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