Bfu38
Bfu38

Reputation: 1141

How to concatenate files from different folders

I have a list of output_[0-293] folders containing a list of files. From each folder I would like to concatenate files with the name:

output_0.txt, output_1.txt, output_2.txt, ...output_293.txt.

How can I achieve this?

Upvotes: 0

Views: 872

Answers (3)

unxnut
unxnut

Reputation: 8839

i=0
while [[ $i -lt 294 ]]
do
    cat output_$i/output_$i.txt >> output.txt
    i=$((i+1))
done

Upvotes: 1

svk
svk

Reputation: 5919

Here's a bash snippet:

for i in `seq 0 293`; do echo output_$i/output_$i.txt; done | xargs cat > /tmp/output_all.txt

Upvotes: 0

SylvainD
SylvainD

Reputation: 1763

Depending on your shell, this might work : cat {folder1,folder2,folder3}/output_*.txt.

It uses brace expansion which is implemented in :

Upvotes: 2

Related Questions