shell - concatenate ordered files using cat on Linux -


i have files 1 n, following:

sim.o500.1  sim.o500.2 . . . sim.o500.n 

each file contains 1 line. want concatenate them in order 1 n.

i tried cat sim.o500.* > out.dat. sadly not work if e.g. n larger 9, because concatenates sim.o500.1 followed sim.o500.10and not sim.o500.1 followed sim.o500.2.

how can loop through file names using numeric order?

since * expands in non-numeric-sorted way, you'd better create sequence seq: way, 10 coome after 9, etc.

for id in $(seq $n)    cat sim.o500.$id >> out.dat done 

note use seq able use variable indicate length of sequence. if value happens fixed , known beforehand, can directly use range expansion writing n value like: for id in {1..23}.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -