Unpack .tar-file and get name


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unpack .tar-file and get name
# 1  
Old 10-18-2010
Unpack .tar-file and get name

Hi there,

I wrote the following code:

Code:
if ($SCENE == *.tar) then
echo "tar -xf $SCENE"
tar -xf $SCENE > tar.txt
set dims = `awk '$0' tar.txt`
echo "name of dims is:"
echo "$dims"
endif

My intension is, to write a variable "dims" with the output name of the tar-command. That means, that my variable should be named the same as the input scene, but without the extension ".tar". I tought I could write a temp txt, write the output name in it and read it afterwards, but the way I wrote the code, the tar.txt is empty.


This seems to be a simple problem. Could anybody help me with this?
Thank you!
# 2  
Old 10-18-2010
If you just want to strip off the "tar.gz", you should look at sed.
That's want you want? To have an output of xyz for ever xyz.tar.gz?
# 3  
Old 10-19-2010
Hm, well, what I need is to unzip the *.tar.gz file. The output is an directory named *. I like to set a variable to *. I need to read files, which the directory * is containing, so I need the name of the directory. The command sed didn`t really help me...
# 4  
Old 10-19-2010
Code:
$ gzcat $SCENE | awk '$0' | read dims

Data in a tar is verbatim like the original except there may be null padding between files, for your tape drive, so the first line of any text file might not be so good.

---------- Post updated at 04:58 PM ---------- Previous update was at 04:55 PM ----------

Maybe this will get rid of nulls:

Code:
$ gzcat $SCENE | tar -xOf - | awk '$0' | read dims

# 5  
Old 10-20-2010
Bug

well, it doesn't work. i've no idea why. can't i just read the name of the variable $SCENE, which stands for the tar.gz or .tar file, without the extension?

variable $SCENE = *.tar.gz
variable $DIMS = *

set DIMS = $SCENE minus .tar.gz

there must be an easy way!

thank you!

---------- Post updated 10-20-10 at 06:48 PM ---------- Previous update was 10-19-10 at 07:14 PM ----------

no one??? SmilieSmilieSmilie

---------- Post updated at 09:53 PM ---------- Previous update was at 06:48 PM ----------

solved, thx
# 6  
Old 10-21-2010
How about this:

Code:
$ SCENE=/tmp/tarball/myprogram_v8.21.0.tar.gz
$ echo $( basename $SCENE .tar.gz )
myprogram_v8.21.0

# 7  
Old 10-21-2010
If you're willing to use ksh or bash, then there is an easy way, yes:


Code:
#!/usr/bin/env ksh

SCENE=/path1/path2/somefile.tar.gz
DIMS=${SCENE%.tar.gz}    
DIMS=${DIMS##*/}             # remove the path if you need to

The % operator causes the contents of the named variable to be examined for the "pattern" that follows between the % and the closing }. If it is there, it is removed and used in the command which is to assign it to DIMS. This doesn't require the start of another process and thus is more efficient than using sed or something else.

If you must use something else, there might be an easy way with the native scripting language (you didn't mention, or I didn't see it), but you can certainly do something like this:

[code]
SCENE=/path1/path2/something.tar.gz
DIMS=`echo "$SCENE | sed 's/.tar.gz//; s!.*/!!'`
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Tar - pre-checking before making the Tar file

Coming from this thread, just wondering if there is an option to check if the Tar of the files/directory will be without any file-errors without actually making the tar. Scenario: Let's say you have a directory of 20GB, but you don't have the space to make Tar file at the moment, and you want... (14 Replies)
Discussion started by: filosophizer
14 Replies

2. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

3. UNIX for Dummies Questions & Answers

UNIX command to check if file name ends with .tar OR if the file is a tar file

Hello Team, Would you please help me with a UNIX command that would check if file is a tar file. if we dont have that , can you help me with UNIX command that would check if file ends with .tar Thanks in advance. (10 Replies)
Discussion started by: sanjaydubey2006
10 Replies

4. UNIX for Dummies Questions & Answers

Do I need to extract the entire tar file to confirm the tar folder is fine?

I would like to confirm my file.tar is been tar-ed correctly before I remove them. But I have very limited disc space to untar it. Can I just do the listing instead of actual extract it? Can I say confirm folder integrity if the listing is sucessful without problem? tar tvf file1.tar ... (1 Reply)
Discussion started by: vivien_chu
1 Replies

5. UNIX for Dummies Questions & Answers

tar -cvf test.tar `find . -mtime -1 -type f` only tar 1 file

Hi all, 4 files are returned when i issue 'find . -mtime -1 -type f -ls'. ./ora_475244.aud ./ora_671958.aud ./ora_934052.aud ./ora_934050.aud However, when I issued the below command: tar -cvf test.tar `find . -mtime -1 -type f`, the tar file only contains the 1st file -... (2 Replies)
Discussion started by: ahSher
2 Replies

6. Shell Programming and Scripting

How to unpack and install .tar.bz2 library ?

Hi, I am trying to unpack and install .tar.bz2 library. I was told to cd / and than tar -jxvf /source-of-library-file?...tar.bz2 to get files unpacked and installed into / Darius $ pwd / $ $ tar -jxvf /tmp/local/root/ncurses-dev-addon.tar.bz2 ncurses-dev-addon/... (3 Replies)
Discussion started by: jack2
3 Replies

7. UNIX for Advanced & Expert Users

Tar utility (untar a .tar file) on VxWorks

Hi All Can someone pls guide me if there any utility to compress file on windows & uncompress on vxworks I tried as - - compressed some folders on windows ... i created .tar ( to maintain directory structure ) and compressed to .gz format. - on VxWorks i have uncompressed it to .tar... (1 Reply)
Discussion started by: uday_01
1 Replies

8. Shell Programming and Scripting

extract one file form .tar.gz without uncompressing .tar.gz file

hi all, kindly help me how to extract one file form .tar.gz without uncompressing .tar.gz file. thanks in advance bali (2 Replies)
Discussion started by: balireddy_77
2 Replies

9. UNIX for Advanced & Expert Users

Does tar do crc checking on a tape or tar file?

Trying to answer a question about whether tar table-of-contents is a good tool for verifying tape data. (1 Reply)
Discussion started by: tjlst15
1 Replies

10. UNIX for Dummies Questions & Answers

does any body know how to unpack this file?????

this file i'm trying to unpack is a cloop file (1 Reply)
Discussion started by: amicrawler2000
1 Replies
Login or Register to Ask a Question