Unix & Linux Stack Exchange
Q&A for users of Linux, FreeBSD and other Unix-like operating systems
Latest Questions
-1
votes
3
answers
120
views
zgrep - Find an IP address in 1200 *.gz files
I want to find out in which of my 1200 *.gz files a certain IP address occurs on a certain date (17.07.2025). I could not find the IP address in my current logs: grep 'IP address' *.logs My attempt to see if the IP even exists in the older, zipped log files returns: 'The argument list is too long'....
I want to find out in which of my 1200 *.gz files a certain IP address occurs on a certain date (17.07.2025).
I could not find the IP address in my current logs:
grep 'IP address' *.logs
My attempt to see if the IP even exists in the older, zipped log files returns: 'The argument list is too long'.
zgrep 'IP address' *
A combination of find and grep was also unsuccessful.
I am grateful for any assistance.
fl1tz
(1 rep)
Jul 21, 2025, 04:18 PM
• Last activity: Jul 25, 2025, 06:22 AM
2
votes
2
answers
14299
views
How to run zgrep with multiple AND patterns?
I know how to do it with `grep`, but the command doesn't work with **zgrep** ``` grep -E 'Pattern1.*Patter2' fileName ``` I'm using **zgrep** to match patterns inside a `.json.gz` file. Because the files are too big, I want to zgrep `BOTH` pattern1 **AND** pattern2, the order doesn't matter. Possibl...
I know how to do it with
grep
, but the command doesn't work with **zgrep**
grep -E 'Pattern1.*Patter2' fileName
I'm using **zgrep** to match patterns inside a .json.gz
file.
Because the files are too big, I want to zgrep BOTH
pattern1 **AND** pattern2, the order doesn't matter.
Possible to achieve?
PlayHardgoPro
(121 rep)
Mar 18, 2022, 01:38 PM
• Last activity: Nov 18, 2024, 04:04 AM
-1
votes
1
answers
141
views
zgrep command not working correctly on command substitution
I am preparing a script that will try to detect two texts on the same line.  This pattern is present in my application log files, which then further used to identify which file contains the pattern. Prepared a script like below: ```bash #!/bin/bash #Takes command line argument# PROC_CNTL_ID="$1...
I am preparing a script
that will try to detect two texts on the same line.
This pattern is present in my application log files,
which then further used to identify which file contains the pattern.
Prepared a script like below:
#!/bin/bash
#Takes command line argument#
PROC_CNTL_ID="$1"
#Extracts the file name#
FILE_NAME="$(zgrep -e 'ERROR.*"$PROC_CNTL_ID"' /opt/applications/cds2/logs/intraday/log/*.gz | cut -d '/' -f 8 | cut -d ':' -f 1 | awk "NR==1")"
#copies to pn02398 user specific directory#
cp -r /opt/applications/cds2/logs/intraday/log/"$FILE_NAME" /home/pn02398/logs/
Now my problem is that the script runs with exit status of 0
but still the copy command is not working.
If I execute zgrep
command by giving a specific value
for the command line argument, it also gives the correct filename.
What's wrong with the command substitution?
Piyush Nikhade
(11 rep)
May 4, 2024, 07:19 PM
• Last activity: May 4, 2024, 10:08 PM
0
votes
3
answers
118
views
How to add column based in the second line match using SED or another command?
I have the following lines result from `zcat` command ```none 1 - URL Template: https://www.test.com 2 - Response: ``` I want to add the line 2 result from call to first line 1 like this ```none URL Template: https://www.test.com ``` Can I do that?
I have the following lines result from
zcat
command
1 - URL Template: https://www.test.com
2 - Response:
I want to add the line 2 result from call to first line 1 like this
URL Template: https://www.test.com
Can I do that?
user13737800
(3 rep)
May 11, 2022, 09:26 PM
• Last activity: May 14, 2022, 05:54 PM
0
votes
0
answers
202
views
How to ignore errors in zgrep reader?
I want to search a directory's contents for a certain string on Ubuntu, and output all files that contain it. Problem: if `zgrep` tries to read a damaged file, the process stops: zgrep -n 'test' /var/log/tomcat/archive/* Result: gzip: /var/log/tomcat/archive/my.log.gz: unexpected end of file Questio...
I want to search a directory's contents for a certain string on Ubuntu, and output all files that contain it.
Problem: if
zgrep
tries to read a damaged file, the process stops:
zgrep -n 'test' /var/log/tomcat/archive/*
Result:
gzip: /var/log/tomcat/archive/my.log.gz: unexpected end of file
Question: how can I tell zgrep
to ignore files that give errors?
membersound
(490 rep)
Mar 21, 2022, 08:05 AM
• Last activity: Mar 21, 2022, 08:30 AM
1
votes
1
answers
1682
views
Zgrep command is not working
I need to search "335664324" in the file `A33256.xml.gz`. I tried the following code. sftp> zgrep -c "335664324" A33256.xml.gz A33256.xml.gz Invalid command. I'm in the same directory as the file. How can I overcome this issue to display the output?
I need to search "335664324" in the file
A33256.xml.gz
. I tried the following code.
sftp> zgrep -c "335664324" A33256.xml.gz
A33256.xml.gz
Invalid command.
I'm in the same directory as the file. How can I overcome this issue to display the output?
Shehan
(11 rep)
Oct 28, 2021, 02:56 AM
• Last activity: Oct 28, 2021, 11:52 AM
0
votes
2
answers
202
views
How to extract few tabs from a xml file using zgrep or sed
I have a big size file like 5GB with `.gz`. Inside that file, we have few XML files that contains values that I want to search and extract just in case if those values are there. For example I want to extract the tags that contains the name `NOOSS` and also the subcontent of this tags like ` `, ` `,...
I have a big size file like 5GB with
.gz
. Inside that file, we have few XML files that contains values that I want to search and extract just in case if those values are there.
For example I want to extract the tags that contains the name NOOSS
and also the subcontent of this tags like `,
,
,
from the the
.gz` file
1
NOOSSCONTROLExample
ACTIVE
FIVE_MIN
MEASUREMENTJOB
HIGH
FIVE_MIN
Sla
CHANGED_ONLY
mr_2
Anything
PER_SECOND
mr_1
ManagedElement=1,SystemFunctions=1,Pm=1,PmGroup=OSProcessingLogicalUnit,MeasurementType=CPULoad.Total
PER_SECOND
I was using cat *gz 1 zgrep -a "PmJobId"
but the output only show the `` value and not the rest of the information or tags.
Please your help, I'm noobie on this.
Im using CentOS - RedHat Linux.
Thanks
Juan Pablo Bustamante Luna
(125 rep)
Sep 29, 2021, 04:26 PM
• Last activity: Sep 29, 2021, 08:36 PM
3
votes
1
answers
2083
views
Fastest way to find lines starting with string in gzip file
I have a flat database based on 65536 files, each one containing one word by line starting with two hexadecimal characters. They look like this: ``` afword 46word2 Feword3 ... ``` I make tens of thousands of requests a day on this, so I'm looking for a better way to find a line starting with two hex...
I have a flat database based on 65536 files, each one containing one word by line starting with two hexadecimal characters.
They look like this:
afword
46word2
Feword3
...
I make tens of thousands of requests a day on this, so I'm looking for a better way to find a line starting with two hexadecimal characters. The files were sorted before being gzipped.
As of now, I do:
LC=ALL zgrep --text '^af' file
Is there any other faster way to do this in perl or bash or any command line?
James
(71 rep)
Aug 22, 2021, 04:29 PM
• Last activity: Sep 5, 2021, 02:30 PM
1
votes
3
answers
2430
views
Slow performance of zgrep in multiple files
I have a **9.8GB** gzip file A.gz and other file i have is **79MB** B.txt which has some text in each line. I want to grep B's text in A.gz and write to a new file. Initially, I used this command zgrep -f B.txt A.gz > C.xml But this command was hanged and it created an empty C.xml for very long time...
I have a **9.8GB** gzip file A.gz and other file i have is **79MB** B.txt which has some text in each line.
I want to grep B's text in A.gz and write to a new file.
Initially, I used this command
zgrep -f B.txt A.gz > C.xml
But this command was hanged and it created an empty C.xml for very long time.
Then after googling I came to know that because B.txt is huge it hangs when it keeps the text in buffer.
So I splitted the text file in 20000 text each
split -l 20000 -a 4 B.txt B
I created files like Baaaa, Baaab....
and then iterated over each file
cd B
for f in B*; do
zgrep -f "$f" ../A.gz >> C.xml
done
It is very slow and still running.
Any better approach for this?
Will gunzipping the gz file will improve performance?
**Update**
I tried with -F
zgrep -F -f "$f" ../A.gz >> C.xml
this is little faster but still want other option
I have xml like
source1
123
ABC
source2
123
XYZ
Here id is same 123 but category is different ABC and XYZ
(Input is limited set of categories e.g ABC,DEF,GHI,JKLM,NOP)
Initially I have category as ABC and So based on the category ABC I find out its id i.e. 123 like this i keep on writing all id's that belong to these input categories to a new file i.e. B.txt(list of id's) like below
zgrep -E 'ABC|DEF|GHI|JKLM|NOP' A.gz | sed -n 's:.*\(.*\).*:\1:p' | uniq > B.txt
later on I iterate over this id's and fetch all xmls, this way I get both xml tags with category ABC and XYZ which belongs to id 123
happy
(63 rep)
May 27, 2020, 06:33 AM
• Last activity: Aug 23, 2021, 10:20 AM
1
votes
1
answers
1518
views
zgrep a column and print the matching filename
I am trying to match pattern for a particular column in the thousands of gzipped files on a Linux machine, and based on the match I want to print the file name how to do that. Below options are not working for me , any suggestions please. Thanks zgrep 12345 *| awk -F"^" '{if($8==12345) print}' find...
I am trying to match pattern for a particular column in the thousands of gzipped files on a Linux machine, and based on the match I want to print the file name how to do that.
Below options are not working for me , any suggestions please. Thanks
zgrep 12345 *| awk -F"^" '{if($8==12345) print}'
find . -type f |xargs zcat | awk -F"^" '{if($8==12345) print}'
Forever Learner
(769 rep)
Sep 24, 2020, 03:00 PM
• Last activity: Sep 24, 2020, 07:02 PM
0
votes
0
answers
269
views
xargs with zgrep is giving the error
I have many gzipped files and I am trying to find some string pattern from the thousands of file but I am getting extra .gz while trying to zgrep it. Please refer the below, could you please advise. Thanks. $ zcat abc.gz 1234^911^is^good this^is^test $ ls *.gz| xargs zgrep 911 gzip: abc.gz.gz: No su...
I have many gzipped files and I am trying to find some string pattern from the thousands of file but I am getting extra .gz while trying to zgrep it. Please refer the below, could you please advise. Thanks.
$ zcat abc.gz
1234^911^is^good
this^is^test
$ ls *.gz| xargs zgrep 911
gzip: abc.gz.gz: No such file or directory
Edit 1: @waltinator, thank you. In the echo it is showing the correct stuff.
$ ls *.gz| xargs echo zgrep 911
zgrep 911 abc.gz
$ ls *.gz| xargs zgrep 911
gzip: abc.gz.gz: No such file or directory
Edit2: find is giving the correct output
$ find . -name *.gz | xargs zgrep 911
1234^911^is^good
Forever Learner
(769 rep)
Sep 11, 2020, 02:18 PM
• Last activity: Sep 14, 2020, 11:12 AM
0
votes
3
answers
976
views
zgrep for multiple pipe symbols in a bunch of gz files
I have a lot of .gz files in a folder /a/b/c1.gz /a/b/c2.gz /a/b/c3.gz and so on. Some of the files have a single pipe delimiter, some have two, three and four and so on, in such a way: xyz|abc xyz|abc|wty xyz|abc|wty|asd and so on. How do I find all the files that have two pipe delimiters overall,...
I have a lot of .gz files in a folder
/a/b/c1.gz
/a/b/c2.gz
/a/b/c3.gz
and so on.
Some of the files have a single pipe delimiter, some have two, three and four and so on, in such a way:
xyz|abc
xyz|abc|wty
xyz|abc|wty|asd
and so on.
How do I find all the files that have two pipe delimiters overall, three delimiters overall etc ?
Sicario007
(3 rep)
May 14, 2020, 01:59 AM
• Last activity: May 14, 2020, 07:14 AM
0
votes
0
answers
193
views
Anyway to provide hint to zgrep to search part of file for faster search results
Production logs file are huge in size and are stored in compressed format. I use the following to find specific log line zgrep searchString LargeLogFiles*.gz Typically this takes huge amount of time, when this runs on multiple files at once. In my case, I am aware that the **search string I'm trying...
Production logs file are huge in size and are stored in compressed format.
I use the following to find specific log line
zgrep searchString LargeLogFiles*.gz
Typically this takes huge amount of time, when this runs on multiple files at once.
In my case, I am aware that the **search string I'm trying to find (if present) will lie in 50% to 70% of the part of the file for sure**. Is there any way I can leverage this information for faster search?
**Possible solution**
zcat the file and filter the part using other unix commands. This is a possbility, but interested to know if there is a good/efficient way to achieve the above said problem.
mtk
(28468 rep)
Jan 22, 2020, 10:07 AM
• Last activity: Feb 9, 2020, 08:22 PM
Showing page 1 of 13 total questions