Redirect text file content from tar archive to stdout (without extract it) (145 Views)
Reply
Occasional Visitor
Maxbester
Posts: 3
Registered: ‎10-09-2012
Message 1 of 6 (145 Views)

Redirect text file content from tar archive to stdout (without extract it)

Hi,

 

I have a TAR archive that contains several text files. I would like to write a script to display (stdout) the content of a file without extracting it in the current directory.

 

Actually I would like to do the same as:

 

tar tf myArchive.tar folder/someFile.txt
cat folder/someFile.txt
rm -R folder

 

but without the rm...

 

I tried this way but it didn't work:

 

tar -xOf myArchive.tar folder/someFile.txt

 

Thanks

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,700
Registered: ‎03-06-2006
Message 2 of 6 (140 Views)

Re: Redirect text file content from tar archive to stdout (without extract it)

Please use plain text.
Occasional Visitor
Maxbester
Posts: 3
Registered: ‎10-09-2012
Message 3 of 6 (135 Views)

Re: Redirect text file content from tar archive to stdout (without extract it)

I do not have gtar, so what should I do to have the same behaviour?
Please use plain text.
Honored Contributor
Patrick Wallek
Posts: 13,711
Registered: ‎06-21-2000
Message 4 of 6 (131 Views)

Re: Redirect text file content from tar archive to stdout (without extract it)

I am not aware of a way to make the HP-UX native 'tar' do this.  I do not think it is possible.

 

If you really need to do this, you can get 'gtar' from the link supplied by Dennis above.

Please use plain text.
Acclaimed Contributor
Dennis Handly
Posts: 24,700
Registered: ‎03-06-2006
Message 5 of 6 (127 Views)

Re: Redirect text file content from tar archive to stdout (without extract it)

>I do not have gtar, so what should I do to have the same behaviour?

 

You get the same software, gtar.

Or write a script to extract to a temp file using pax, cat, then remove.

Please use plain text.
Occasional Visitor
Maxbester
Posts: 3
Registered: ‎10-09-2012
Message 6 of 6 (116 Views)

Re: Redirect text file content from tar archive to stdout (without extract it)

@: right, this is what I am going to do. Thanks

Please use plain text.
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation