Rafat
Rafat

Reputation: 137

How to read sorted files using cat in shell script

I'm fairly new in this world, so facing this simple problem..

I'm trying to concatenate some files to a single file 'average_all'. The files are by default sorted like below:

  1. aveS0
  2. aveS100
  3. aveS125
  4. aveS150
  5. aveS175
  6. aveS200
  7. aveS225
  8. aveS25
  9. .
  10. .
  11. .

so when I use

cat aveS* > average_all

it reads and then concatenates them according to the sort as above, but I really want it to be concatenated numerically like this:

  1. aveS0
  2. aveS25
  3. aveS50
  4. aveS75
  5. aveS100
  6. .
  7. .

I know that ls -1v aveS* command will sort the files numerically but when I try to use 'cat' command it always reads from the default sort. Any idea how can I make it read the files in a numerical order and concatenate in the same manner? Hope I made it clear. Thanks in advance!

Upvotes: 1

Views: 826

Answers (1)

Related Questions