This script lists the name of the file ( in a tar archive) containing a pattern.
tar tf myarchive.tar | while read -r FILE
do
if tar xf test.tar $FILE -O | grep "pattern" ;then
echo "found pattern in : $FILE"
fi
done
My question is:
Where is this feature documented, where $FILE is one of the files in the archive:
tar xf test.tar $FILE
This is usually documented in man pages, try running this command:
Unfortunately, Linux has not the best set of man pages. There is an online copy of tar manpage from this OS: http://linux.die.net/man/1/tar and it is terrible. But it links to
info mancommand which is command to access the “info” system widely used in GNU world (many programs in linux user-space are from GNU projects, for example gcc). There is an exact link to section of onlineinfo tarabout extracting specific files: http://www.gnu.org/software/tar/manual/html_node/extracting-files.html#SEC27I may also recommend documentation from BSD (e.g. FreeBSD) or opengroup.org. Utilities can be different in detail but behave same in general.
For example, there is some rather old but good man from opengroup (XCU means ‘Commands and Utilities’ of the Single UNIX Specification, Version 2, 1997):
http://pubs.opengroup.org/onlinepubs/7908799/xcu/tar.html
And to fully understand command
tar xf test.tar $FILEyou should also read aboutfoption:So,
test.tarin your command will be used byfkey as archive name; then x will use second argument ($FILE) as name of file or directory to extract from archive.