search="123"
tar -tf one.tar | while read filename
do
        if [ -f "${filename}" ]
        then
                mv "${filename}" "${filename}.sav"
        fi
        #
        tar -xf one.tar "${filename}"
        #
        found=`grep -l "${search}" "${filename}"`
        if [ ! "${found}""X" = "X" ]
        then
                echo "Found \"${search}\" in \"${found}\""
                grep "${search}" "${filename}"
                echo ""
        fi
        #
        if [ -f "${filename}.sav" ]
        then
                mv "${filename}.sav" "${filename}"
        fi
done

Leave a Reply