I hope this fits the category "programming question".
I have a tar-archive containing the folowing structure:
Folder1/File1
Folder2/File2
Folder3/File3
Folder4/File4
My goal is to extract specific contents from this archive (which is huge and therefore called hugeArchive.tar) in the following.
The data to extract is automatically generated and given to me via textfile "filesToExtract.txt".
Content of "filesToExtract.txt":
Folder1
Folder1/File1
Folder2
Folder2/File2
So I thought this task should be easy and I will do achieve it using
cat filesToExtract.txt | xargs tar -xvf hugeArchive.tar
On SunOS 5.10 this performes as expected but on Linux Redhat 6.8 I receive errors (though the general extraction still seems to work because the files are available afterwards)
Output SunOS 5.10:
x Folder1, 0 bytes, 0 tape blocks
x Folder1/File1, 386 bytes, 1 tape blocks
x Folder2, 0 bytes, 0 tape blocks
x Folder2/File2, 858 bytes, 2 tape blocks
Output on Linux Redhat 6.8:
Folder1/
Folder1/File1
Folder2/
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Folder2/File2: Not found in archive
tar: Exiting with failure status due to previous errors
I have no idea what is causing that so I played around and manually changed the input file filesToExtract.txt
to look like this instead:
Folder1/File1
Folder2/File2
Now it works on Linux, witout any error messages. This made me wonder: Maybe this is an overwriting problem? Or maybe the tar tool somehow only allows accessing each file only one time?
I created another kind of test and changed filesToExtract.txt
again and included a duplicate there:
Folder1/File1
Folder2/File2
Folder1/File1
...and there we have the identical error from the first attempt again:
Folder1/File1
Folder2/File2
tar: Folder1/File1: Not found in archive
tar: Exiting with failure status due to previous errors
I am clueless what is behind it (acutally tar should overwrite without complaining, shouldn' it?). Do you have any idea? Is my command wrong? What will I have to change, that it works on Linux without having to change the filesToExtract.txt
.
By the way I am using the standard tar implementation on both systems.
Thanks a lot in advance!
EDIT:
tripleee suggested to rather use
xargs tar -xvf hugeArchive.tar <filesToExtract.txt
since this is a command using redirection. But this is only for the sake of clearness/effectivity and won't affect the overall problematic behaviour