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?
# 8  
Old 01-08-2009
You need:
Code:
uncompress -c test.tar.Z | tar xfq - folder1/obj/one.txt

# 9  
Old 01-08-2009
Question

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 Smilie
# 10  
Old 01-08-2009
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".
# 11  
Old 01-08-2009
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.Smilie
# 12  
Old 01-08-2009
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";
Smilie
# 13  
Old 01-08-2009
You can actually shorten it just a wee bit. Differences in bold:

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

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