Linux read specific content file from tar.gz files without extracting

Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Linux read specific content file from tar.gz files without extracting
# 1  
Wrench Linux read specific content file from tar.gz files without extracting

hello

i wish to write the result of these below conditions in a file:

1. in a specific folder, i have many tar.gz files.
2. each tar.gz file contains ".dat" file in sub folders.
3. i wish to get the full path of these .dat files, if i find in it a specific word ("ERROR24").
4. all this wihtout extracting the tar.gz files


i have found and tested the below one that writes in a file the result, but i don't how to look in a tar.gz file.
there are too many tar.gz to be done manually...

Code:
grep -rlw --include="*.dat" -e "ERROR24" /home/tests/logs > /home/files/data/result/listErrors.txt


can you please help update the previous request in order to get the same result but searching in each tar.gz files present in the specific folder?

thanks for your help.


Moderator's Comments:
Mod Comment Please use CODE tags as required by forum rules!

Last edited by RudiC; 11-01-2017 at 04:12 PM.. Reason: Added CODE tags.
# 2  
You can't search / grep / analyze files that are compressed / zipped etc. with the "normal" *nix text tools as data are no text any more.
Did you consider e.g. zgrep?
# 3  
thanks for your advice.
so it means all i have to do is to test like that?
(i can't test right know... i don't have my linux laptop... tomorrow i'll be able to)

Code:
zgrep -rlw --include="*.dat" -e "ERROR24" /home/tests/logs > /home/files/data/result/listErrors.txt

---------- Post updated 11-02-17 at 02:42 AM ---------- Previous update was 11-01-17 at 02:10 PM ----------

Quote:
Originally Posted by RudiC
You can't search / grep / analyze files that are compressed / zipped etc. with the "normal" *nix text tools as data are no text any more.
Did you consider e.g. zgrep?
hello
it is not working... i am getting this :

Code:
/usr/bin/zgrep: -rlw: option not supported

do you see how i could do that please?
# 4  
Did you consult the man page? man zgrep:
Quote:
These grep options will cause zgrep to terminate with an error code: (-[drRzZ]|--di*|--exc*|--inc*|--rec*|--nu*).
# 5  
it seems that you can't red the content wihtout extracting...
so i need to extract before applying the grep -r
# 6  
Not necessarily - you can implement recursion by other means, e.g. the find command.
# 7  
Quote:
Originally Posted by jimmyjames9
It seems that you can't read the content without extracting...
Literally true, even with tools like zgrep. What zgrep actually does is gunzip < inputfile | grep ... so decompression is not skipped, it just avoids making a temp file. And it's definitely not meant for tar files.
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #890
Difficulty: Easy
In sed, the REGEX dot (.) matches exactly one character.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

I want to read the content of a specific folder

Why does not work a cd in a shell schript file. How do you get to run it? I use these code: #!/bin/sh cd workspace array=($(ls -d */)) echo ${array} But it doesn't change to workspace editby bakunin: please user CODE-tags as required by the rules. Thank you. (12 Replies)
Discussion started by: Linuxmann
12 Replies

2. Red Hat

Moving of file content to another two files after searching with specific pattern

Hello, Please help me with this!! Thanks in advance!! I have a file named file.gc with the content: 1-- Mon Sep 10 08:53:09 CDT 2012 2revoke connect from FR2261; 3delete from mkt_allow where grantee = 'FR2261'; 4grant connect to FR2261 with '******'; 5alter user FR2261 comment... (0 Replies)
Discussion started by: raosr020
0 Replies

3. Shell Programming and Scripting

Extracting content from a file in specific format

Hi All, I have the file in this format **** Results Data **** Time or Step 1 2 20 0.000000000e+00 0s 0s 0s 1.024000000e+00 Us 0s 0s 1.100000000e+00 1s 0s 0s 1.100000001e+00 1s 0s 1s 2.024000000e+00 Us Us 1s 2.024000001e+00 ... (7 Replies)
Discussion started by: diehard
7 Replies

4. UNIX for Advanced & Expert Users

extracting multuiple tar files with while and read

Is anyone out there? I'm trying to run a script i wrote that extracts multiple .tar files in succession by pasting it into standard input. It does extract them all but I cant get it to stop looping and when I hit enter I get a tar command error like its still looking for files to extract. ie; ... (2 Replies)
Discussion started by: commoja
2 Replies

5. UNIX for Dummies Questions & Answers

Extracting specific files from a tar file in HP-UX

I have tried: tar -xfv mytarfile.tar archive/tabv/* tar -xfv mytarfile.tar --wildcards 'archive/tabv/*' tar -xf mytarfile.tar -v --wildcards 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards --no-anchored 'archive/tabv/*' tar -xfv mytarfile.tar --wildcards `archive/tabv/*` and none... (5 Replies)
Discussion started by: zapper222
5 Replies

6. Shell Programming and Scripting

Extracting .tar files.

Hey guys complete n00b here so I'll try my best at explaining. I'm creating a backup and restore utility and decided to use tar. I create a backup folder in each user's account and when backing up (say word processing files), I use the following: tar cvf /home/user/backup/wpbackup.tar... (2 Replies)
Discussion started by: EwanD
2 Replies

7. Shell Programming and Scripting

How to read the content of the particular file from tar.Z without extracting?

Hi All, I want to read the content of the particular file from tar.Z without extracting. aaa.tar.Z contains a file called one.txt, I want to read the content of the one.txt without extracting. Please help me to read the content of it. Regards, Kalai. (12 Replies)
Discussion started by: kalpeer
12 Replies

8. Shell Programming and Scripting

Read specific file from a zip archive without extracting

Hi All, I would like to extract specific file from a zip archive. I have a zip archive "sample.zip". sample.zip contains few text files and images... text1.txt, text2.txt, pic.jpg etc... I need to read specific file "text2.txt" from "sample.zip" WITHOUT EXTRACTING the zip file. ... (4 Replies)
Discussion started by: sridharg
4 Replies

9. Shell Programming and Scripting

bash - batch script for extracting one file from multiple tar files

so i have hundreds of files named history.20071112.tar (history.YYYYMMDD.tar) and im looking to extract one file out of each archive called status_YYYYMMDDHH:MM.lis here is what i have so far: for FILE in `cat dirlist` do tar xvf $FILE ./status_* done dirlist is a text... (4 Replies)
Discussion started by: kuliksco
4 Replies

10. UNIX for Dummies Questions & Answers

Is extracting specific files from a zip file possible?

If a zip file contains several zip files, but if the file names of the files needed are known, is there a variation of the unzip command that will allow those few (individual) files to be extracted? --- Example: Zip file name: zip.zip unzip -l zip.zip will display file01, file02, file03, etc.... (1 Reply)
Discussion started by: HLee1981
1 Replies