Reputation: 1316
I have a directory structure like this:
Y1/year1fileA.txt.gz
Y1/year1fileB.txt.gz
Y2/year2fileA.txt.gz
Y2/year2fileB.txt.gz
Y3/year3fileA.txt.gz
Y3/year3fileB.txt.gz
Y4/year4fileA.txt.gz
Y4/year4fileB.txt.gz
...
I was planning on passing the <(zcat ./Y1/year1fileA.txt.gz ./Y2/year2fileA.txt.gz ...)
in that order into another command that expects FILE
and not stdin
.
I thought of using:
command <(find . -name "*fileA*.gz" -exec zcat {})
After running it, I realized the files where not passed into zcat in a sorted fashion (i.e. year4fileA.txt.gz
was written before year1fileA.txt.gz
)
Is there a way to use find
and sort these files before passing to zcat
? Or should I use for loops? or xargs
?
Upvotes: 0
Views: 232
Reputation: 361585
find
doesn't sort its output, but globs do. A glob that matches all of the files at once ought to suffice:
cmd <(zcat Y*/year*file*.txt.gz)
Upvotes: 3