Search code examples
linuxawktarwc

How to take count some data of a file which is in archived folder?


I have a archived folder which contain some files, from one of those files I want to take count of 31 delimiter. How to get count without unzipping folder?

archived folder name =mug.tar, file name = APR_17

Below is how to take count

| awk -F "|" '{print $31}'|grep "40411"|sort -n|uniq -c|wc –l

Solution

  • Untar the wanted file from the archive file to stdout and pipe it your awk:

    $ tar -xOf mug.tar APR_17 | awk ...
    

    man tar:

     -x, --extract, --get
           extract files from an archive
    
     -O, --to-stdout
           extract files to standard output
    
     -f, --file ARCHIVE
           use archive file or device ARCHIVE