[wellylug] a bit of data bashing

Olly Betts olly at survex.com
Tue Mar 24 14:15:23 NZDT 2015


On Tue, Mar 24, 2015 at 09:09:20AM +1300, Christian Arndt wrote:
>   $ for i in {1..10}; do echo file00000$i.whatever >> filname.txt ;done

While Grant's use of seq to generate the file is a better answer, I've
seen patterns like the above in other cases which couldn't just be done
with seq.

Although this works, be aware that it will open and close "filname.txt"
for every iteration of the loop - if you're looping a lot, that can add
up.  Better to just redirect output for the whole for loop instead:

    $ for i in {1..10}; do echo file00000$i.whatever ;done > filname.txt

That's assuming you didn't actually want to append to whatever was in
"filname.txt" to start with - if you did, you can just use >> here.

Timing with {1..1000000}, this version is about twice as fast for me.

Cheers,
    Olly



More information about the wellylug mailing list