One possible way, if I understand your question...
Quote:
Originally Posted by skwyer
I'm running an sh shell that is unzipping some zip files that have a directory structure on them.
Is there a way I can find the top level directory in the zip file and assign that to a variable?
mike
Say you have a directory structure that looks like this:
and you tarball it up into test.tar.gz.
Then one way to find assign the top level of the directory structure (test1) to a variable is to do the following
We assign the value to the DIRECTORY_VARIABLE using command substitution, $(). The commands to get the answer take care of splitting the parts we need to the final name.
First, tar -tzvf test.tar.gz will list the table of contents of the tar file. You need -z to take care of the decompression. The output of that alone looks like this:
That's piped to the first cut command that splits the output above into fields separated by spaces (-d" "). If you count the output above like that, you can see that the information that we need is held in field six (-f6). What we end up with is this:
Closer, but not quite there.
The second cut statement will trim off the fat. It separates on fields delimited by slashes (-d"/") and we want the first field (-f1). It ends up looking like this:
Closer still, but we don't want all of those results stuffed into our variable, so the final head statement just pulls the top value. We could have used other methods like piping to sort and then uniq or using "tail -1," but this works.
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Hello All,
Hope you're doing well !
I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted.
header_date_14=$(m_dump... (8 Replies)
Hi,
need to zip all files in a directory and move to another directory after the zip..
i am using this one but didnt help me...
zip -r my_proj_`date +%Y%m%d%H%MS`.zip /path/my_proj
mv in_proj_`date +%Y%m%d%H%M%S`.zip /path/source/
i am trying to zip all the files in my_proj... (0 Replies)
How can I assign a variable to an variable. IE $car=honda
One way I can do it is export $car=honda
or
let $car=2323
Is there any other ways to preform this task (3 Replies)
Hi,
Im facing a problem that im stucked,
I have the following structure:
thales@pereirtc-vbox:/home/VfARM$ ls
code config doc lib manifest.bak manifest.rel manifest.v3 ns pub
if i try to execute zip -q -o arm.zip VfARM/* it will create a zip file with the folder VfARM.... (2 Replies)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
I have two files in a directory:
xxxx.txt
xxxx.csv
I need to zip both files up but the command I am doing below is only zipping xxx.txt file????:
cd ../$CUSTOMER_DIRECTORY
zip -q ${name}${FILE_OUT_NAME}.zip ls -lrt *.csv *.txt
can anyone help?:confused: (3 Replies)