1

I have a file named file1.txt that contains the lines:

e1.txt
e2.txt

These are files themselves existing in the same directory.

I want to use an awk command on file1.txt so as to read its contents(e1.txt and e2.txt) and print the contents of those files

I have tried awk '{cat $0}' file1.txt but it produces no result.

2

You need a getline loop around each file (e1.txt, e2.txt etc) contained in file1.txt, like so

awk '{ while ((getline a < $0) > 0) print a }' file1.txt

Alternately you could call out to cat via system but this could be fraught with peril if the contents of file1.txt are not under your control

 awk '{ system("cat "$0) }' file1.txt

Or just don't bother with awk

 xargs -d '\n' cat <file1.txt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.