Find the answer to your Linux question:
Results 1 to 4 of 4
Hello there, I'm relatively new to Unix, and I would like to know the commands/script for searching within files inside a tarball(.tar file). Let's say I have a file ABC.tar, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2

    Searching within files in a tarball archive (.tar)


    Hello there,

    I'm relatively new to Unix, and I would like to know the commands/script for searching within files inside a tarball(.tar file).

    Let's say I have a file ABC.tar, that contains many files such as X.txt, Y.txt, Z.txt.. One of these files (X,Y,Z..) contains a string 'Hello'. How can i grep within the .tar file to find which file contains the string 'Hello', without extracting the .tar?

    Thanks.

  2. #2
    Just Joined!
    Join Date
    Jul 2012
    Posts
    10
    Code:
    F=`tar --list -x ABC.tar`
    for Z in $F; do 
      if tar -xOf ABC.tar $Z | grep Hello ; then 
        echo found in $Z
      fi
    done

  3. #3
    Linux Newbie hagfish52's Avatar
    Join Date
    Dec 2011
    Location
    Asheville, NC
    Posts
    225
    This works for me:

    Code:
    tar -O --wildcards -xf ABC.tar | grep -I -r -i 'Hello' ./

  4. #4
    Just Joined!
    Join Date
    Jul 2012
    Posts
    2
    Quote Originally Posted by hagfish52 View Post
    This works for me:

    Code:
    tar -O --wildcards -xf ABC.tar | grep -I -r -i 'Hello' ./
    Thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •