简体   繁体   中英

multiple files from different directory as input to awk

I have different files with same file names and they are stored in different directories such as

/path/to/2000/{a,b,c}.txt ... /path/to/2001/{a,b,c}.txt

since I want to use variables to represent the directories like

/path/to/{1998..2013}/{a.b.c}.txt

and how can I parametrize the directory name to input like

awk '....' /path/to/{$start..$end}/{a,b,c}.txt

please be noted that I cannot loop all directories to input file one by one to the awk since the awk script needs all information from those files at the same time. thx for helping.

You can use eval:

eval awk '...' /path/to/{$start..$end}/{a,b,c}.txt

Or find and xargs, but it is not as accurate:

find /path/to -path '*/[21][90][09][0-9]/[abc].txt' | xargs awk '....'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM