Extract a tar ball into multiple directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Extract a tar ball into multiple directories
# 1  
Old 06-15-2015
Extract a tar ball into multiple directories

Code:
#cat a
BAC064DAL
BAC063DAL
BAC056PHX
BAC066DAL
BAC062PHX
BAC062DAL
BAC060DAL
BAC058PHX
BAC054PHX
BAC051PHX


[root]# for i in `cat a`
> do
> tar xvf $a/$a*.tar*
> done
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
tar: /*.tar*: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
[root@logserver logger]#

# 2  
Old 06-15-2015
As you see, the program tar is telling you that it can not find any file with such name.
What name is that?
Whatever this expands to $a/$a*.tar*
Which in this case is pretty much garbage since the variable $a does not exist, in your code.


Assuming you want to extract all those files in the file a:
Code:
#cat a
BAC064DAL
BAC063DAL
BAC056PHX
BAC066DAL
BAC062PHX
BAC062DAL
BAC060DAL
BAC058PHX
BAC054PHX
BAC051PHX

Code:
while read f; do tar xvf /path/to/"${f}".tar; done < a

Replace /path/to with the directory path you need and fix the extension of the file if it is a tar.

Last edited by Aia; 06-15-2015 at 01:56 PM..
# 3  
Old 06-15-2015
Try replacing "$a" with "$i".
# 4  
Old 06-15-2015
Can you please elaborate what exactly is your requirement here
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create Tar ball

Hi Team, Following unix command is throwing error. Can anyone please help me to fix the issue? tar -cvf /aa/bb/cc/tarball1.tar /x/y/z1/abc.ksh /x/y/z2/pqr.txt /x/y/z3/lmn.tmp Error message thrown: tar: Removing leading `/' from member names OS: uname -a Linux xyz... (1 Reply)
Discussion started by: kmanivan82
1 Replies

2. Shell Programming and Scripting

Problem creating a tar ball in different directories

Hi all. I'm hitting a problem creating a tar archive in one directory from files located in a different directory. It fails when I replace the absolute paths with variables in the script but works if I just run tar on the cmdln. E.g. #!/bin/ksh BASE=$PWD STAGE=$BASE/stage LOG=$BASE/log... (4 Replies)
Discussion started by: user052009
4 Replies

3. Shell Programming and Scripting

Untar only folder structure from a tar ball

I have a tar file hello.tar which is 95 GB. hello.tar has many files and folders including some tar files as well. I wish to create a new tar ball which should maintain only the folder structure of hello.tar and the tar ball within the hello.tar So basically the idea is to untar... (2 Replies)
Discussion started by: mohtashims
2 Replies

4. Shell Programming and Scripting

Need Tar Ball command to exclude directories

Hi, uname -a SunOS mymac 5.11 11.2 sun4u sparc SUNW,SPARC-Enterprise I need to tar a folder /tmp/moht but do not want these three folders to be included in the tar file -> savejpg, bmpsave and imgsave I tried --exclude, -path, -not options but it says bad option Can you help me with... (3 Replies)
Discussion started by: mohtashims
3 Replies

5. Shell Programming and Scripting

Tar extract a multiple directories

i extract it through script, is there any way to script or automate to tar extract a tarfiles in multiple directories at once? Cannot open: No such file or directory tar: Error is not recoverable: exiting now for dir in `ls -d /tarfiles/*/ | sed 's/.$//'` do rm -f $dir/*.tar mv -f... (1 Reply)
Discussion started by: kenshinhimura
1 Replies

6. UNIX for Advanced & Expert Users

Extracting directories only from tar ball

Hi Somebody must have done this before, but I can't seem to find any answer on my problem. On HP-UX 11i v3 I have a relatively large tar ball (~120 GB), and I want to create the directory structure only from the archive. There is no option to make a new archive with only the directory... (3 Replies)
Discussion started by: hpvm_adm
3 Replies

7. Shell Programming and Scripting

Extract files from tar ball without directory structure

Hi, I have tar filw which has multiple directories which contain files. When i extract using tar -xf the directory structure also get extracted. I require only files and not directory structures as there will be overhead of moving the files again. So i searched here and got a solution but... (4 Replies)
Discussion started by: chetan.c
4 Replies

8. Shell Programming and Scripting

Extract contents of tar ball without extracting files

Hi, I'm using a tar command tar -xOvf /home/mytar.tar My intention is to extract data in files which are inside various directories, without extracting files to the disk. Is this the best way to achieve it? Thanks, Chetan (3 Replies)
Discussion started by: chetan.c
3 Replies

9. Solaris

How to extract files from a tar file without creating the directories?

Hello all. I have a tar file that contains a number of files that are stored in different directories. If I extract this tar file with -xvf , the directories get created. Is there a way to extract all of the files into one directory without creating the directories stored in the tar file. (9 Replies)
Discussion started by: gkb
9 Replies

10. BSD

tape drives vs. tar with multiple directories

Hello, I have a little problem with backup & restoring files from tape drive. I am adding 3 directories to my tape, and it is OK: hades# tar -cvf /dev/nsa0 test test1 restore a test a test/level1 a test/myharddisk.img a test1 a test1/level1 a test1/myharddisk.img a test1/test.img a... (1 Reply)
Discussion started by: d3m00n
1 Replies
Login or Register to Ask a Question