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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to read the content of the particular file from tar.Z without extracting?
# 1  
Old 01-07-2009
Data 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.
# 2  
Old 01-07-2009
Quote:
Originally Posted by kalpeer
I want to read the content of the particular file from tar.Z without extracting.

Use the -O option to extract to standard output instead of to a file.
# 3  
Old 01-07-2009
Bug

I have used the following command to view the comtent of the file

zcat test.tar.Z | grep tmp/one.txt

it display the output of one.txt

now i want to assign tat output to some perl variable. so tat i can use in some perl file
# 4  
Old 01-07-2009
Quote:
Use the -O option to extract to standard output instead of to a file
.

Sadly, this works only if one is using GNU tar or an advanced tar. Since this is a .Z file, you might not have that available.

You'll also have to decompress. If using GNU tar, you can do:
Code:
tar xzfO tarfile.tar.Z archive/to/extract/file

Otherwise, you'll have to extract the file, cat it, and remove it. On Solaris, you can do:
Code:
uncopmress -c file.tar.Z | tar xfq - archive/to/extract/file ; cat archive/to/extract/file; rm archive/to/extract/file

The 'q' options quits as soon as the file has been extracted, closing the pipeline, thus allowing uncompress to stop as soon as possible. You can then make a script to do all this for you.

Last edited by otheus; 01-07-2009 at 09:46 AM.. Reason: orretion
# 5  
Old 01-07-2009
i have tried the following command in prompt

uncompress -c | tar xfq test.tar.Z | grep one.txt

it shows some error saying
tar: directory checksum error

please help me to read the value and store it to some variable

or

please help me to extract only tat particular file to some location ,so tat i can remove once i done with tat.
# 6  
Old 01-07-2009
Ooops! I have corrected my original edit. I put the filename in the wrong place!
# 7  
Old 01-08-2009
Data

I have tried the following

uncompress -c test.tar.Z | tar xfq - one.txt

the location of one.txt is

folder1/obj/one.txt

but it does not uncopress tat file

When i tried the following comment

uncompress -c test.tar.Z | tar xfq - folder1


it extracts the folder1..

Now please help me to extarct the file
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

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... (6 Replies)
Discussion started by: jimmyjames9
6 Replies

2. OS X (Apple)

Uncompressing but not extracting tar.Z file

Hi I have a few hundred files with extension .tar.Z. These files were archived (tar) and compressed (Z) on a UNIX system. I need to unzip them but not extract them. In other words they need to go to .tar extension. I would like to do this on my MAC or on a windows pc. I do not have a UNIX... (3 Replies)
Discussion started by: kalbano
3 Replies

3. Shell Programming and Scripting

Extracting content from xml file

Hello All, Hope you are doing well!!!!! I have a small code in the below format in xml file: <UML:ModelElement.taggedValue> <UML:TaggedValue tag="documentation" value="This sequence&#xA;&#xA;HLD_EA_0001X&#xA;HLD_DOORS_002X"/> <UML:TaggedValue tag="documentation" value="This... (11 Replies)
Discussion started by: suvendu4urs
11 Replies

4. 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

5. 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

6. Shell Programming and Scripting

Extracting content of a file

Hello, I'm working on a script to extract the contents of a file (in general, plain txt file with numbers, symbols, and letters) and output it into a .txt file. but it is kind of all over the place. It needs to not include duplicates and the content has to be readable. I jumped all over the place... (7 Replies)
Discussion started by: l20N1N
7 Replies

7. Solaris

option to delete .tar file while extracting

Is there an option in tar which deletes the .tar file as soon as it is successfully extracted. (5 Replies)
Discussion started by: vickylife
5 Replies

8. UNIX for Dummies Questions & Answers

Extracting from a tar archive file

Can I extract files from an archive file (tar), where the filename includes the full directory path, to a different directory? For example the archive files may have a filename of /SrcFiles/XXX/filename.dat and I want to extract it to /SrcFiles/YYY/filename.dat. Since the archive file was... (1 Reply)
Discussion started by: nmalencia
1 Replies

9. UNIX Desktop Questions & Answers

Extracting from a tar file

Can I extract files from an archive file (tar), where the filename includes the full directory path, to a different directory? For example the archive files may have a filename of /SrcFiles/XXX/filename.dat and I want to extract it to /SrcFiles/YYY/filename.dat. Since the archive file... (1 Reply)
Discussion started by: nmalencia
1 Replies

10. UNIX for Dummies Questions & Answers

extracting from a tar file

Dear experts I have received a tar file containing several files with full path. Now I need to restore it in another system but when I want to extract files by using tar -xvf tarfile it wants to create all files with full paths again in new system in which I don't have enough previleges. How... (4 Replies)
Discussion started by: Reza Nazarian
4 Replies
Login or Register to Ask a Question