Unpack .tar-file and get name

Hi there,

I wrote the following 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!

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?

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

$ 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:

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

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??? :o:o:o

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

solved, thx

How about this:

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

If you're willing to use ksh or bash, then there is an easy way, yes:

#!/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!.*/!!'`