Sean
Sean

Reputation: 1313

Concatenating many similar files

If I have a bunch of files labelled like the following:

fasta_Watson_0
fasta_Watson_1
fasta_Watson_2
...
fasta_Watson_190

How would I write an awk script to automate concatenating all the files into one?

Hand typing:

cat fasta_Watson_0 fasta_Watson_1 ...

is just way too tedious!

Upvotes: 1

Views: 62

Answers (2)

John1024
John1024

Reputation: 113834

To cat them all in numerical order and save the result in a file named output, use:

cat fasta_Watson_{0..190} >output

The construct {0..190} is a bashism representing all numbers from 0 to 190. If your shell doesn't support that, you can use the standard utility seq:

cat $(seq -f 'fasta_Watson_%g' 0 190) > output

Upvotes: 1

abarry
abarry

Reputation: 423

You can use bash wildcards, but you'll have to worry about sort order. Might do something like suggested on this post.

cat `ls fasta_Watson_* |sort -n -t "_" -k 3`

Upvotes: 3

Related Questions