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.

Use the -O option to extract to standard output instead of to a file.

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

.

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:

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:

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.

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.

Ooops! I have corrected my original edit. I put the filename in the wrong place!

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

You need:

uncompress -c test.tar.Z | tar xfq - folder1/obj/one.txt

When i try the following comment

uncompress -c test.tar.Z | tar xfq - folder1/obj/one.txt

it extracts the entire folder1 not tat particular file.

Please help me :confused:

No, it extracts that one particular file but creates all the folders leading up to it. So first remove folder1 (rm -rf folder1), do the above command. Then you will see folder1 with only "obj" and inside obj, only "one.txt".

Thanks a lot , I got it in command prompt.Now i need to read through script.
I have used the below code to read tat content of the file through perl script.

$d="uncompress -c test.tar.Z | tar xfq - folder1/obj/one.txt";
open(VERSION,$d) || print ("\nMissing 'INFO' file \n");
while (<VERSION>) {
chop;
$newVersion=$_;
print "$newPerlVersion";
}
close PERLVERSION;

But am not able to retrieve it.:frowning:

I got the solution for above asked question
i have used the following code

$d="uncompress -c test.tar.Z |tar xfq - folder1/obj/one.txt";
system $d;
open(VERSION,"folder1/obj/one.txt") || print ("\nMissing 'INFO' file \n");
while (<VERSION>) {
chop;
$newlVersion=$_;
print "$newlVersion";
}
close VERSION;
system "rm -rf folder1";
:b:

You can actually shorten it just a wee bit. Differences in bold:

 
system <uncompress/untar command here>
open(VERSION,"folder1/obj/one.txt") || die ("\nMissing 'INFO' file \n");
while (<VERSION>) { print; }
system "rm -rf folder1";