robinwood13
robinwood13

Reputation: 199

Zcat + awk with absolute path

In my "test.tar.gz" there is a text file : "test.txt" with :

col1 {tab} col2 {tab} col3

-

The problem is, when I run it :

zcat ./folder1/test.tar.gz | awk -F '\t' '{print $1, $3}'

It returns :

test.txt

So if I add :

zcat ./folder1/test.tar.gz | awk -F '\t' '{print $1, $3}' test.txt

It returns :

awk: cannot open test.txt (No such file or directory)

Thanks by advance !

Upvotes: 1

Views: 1021

Answers (2)

robinwood13
robinwood13

Reputation: 199

tar -xzf ./folder1/test.tar.gz test.txt -O | awk -F '\t' '{print $1, $3}'

Works perfectly. Thanks everybody !

Upvotes: 0

Tom Fenech
Tom Fenech

Reputation: 74625

Try using something like this:

tar -xzOf test.tar.gz test.txt | awk '{print $1, $3}'

This extracts the file test.txt from the archive. The -O switch sends the contents of the file to standard output, which can then be piped to awk.

Upvotes: 3

Related Questions