Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

grep on both zip and non zip files

when i do ls -ltr i see bunch of .gz files says 123.gz and 456.gz
and bunch of no gz files say 789.log etc

how to grep on say "testing" on both zip gz files and non zip files

grep "testing" 789.log

zgrep "testing"  123.gz

not sure how to combine above two together

also how search today log between 10 am to 11 am for that "testing" word in log?
please advise
Avatar of serialband
serialband
Flag of Ukraine image

You can just use zgrep for both. zgrep will search plain text as well as compressed files
zgrep "testing" 123.gz 789.log
zgrep "testing" *.gz *.log
If you're searching may text + .gzip files, you can always do this in your shell startup file...

alias grep=zgrep

Open in new window

Avatar of gudii9

ASKER

zgrep "testing" 123.gz 789.log
zgrep "testing" *.gz *.log

in the result how to know whether it found in .gz file or .log file

please advise
The search term shows up as

123.gz: Filename followed by a colon, then whatever the line is here that includes your search term "testing"
789.log: another line with the word testing in it.

You should probably just run the command to see what you get.
Avatar of gudii9

ASKER

123.gz

has 10 different files(file1,file2...file10) which it list one of that file rather than saying it as 123.gz
some kind of relative path would have helped like
found testing at line 159
123.gz/file2
etc
Seems like your original question has been answered.

Go ahead + close this question + open another question related to your last update. Also provide more detail, as your last update requires much more detail for an answer.
I don't believe gzip can make an archive of 10 different files without using tar. Usually it is named tar.gz in that case.

If it is a tar archive, then you can view the files inside of it.

tar -tf 123.gz

If someone took ten files and concatenated them into a gzip file, then sorry the filenames are lost.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.