How to write a complete awk script

, par  Valerio D. Ciotti , popularité : 2%

I’ve the following situation :

I have a file of 1 column data containg only nubmbers. Let’s call it file.dat .

Then I’ve to shuffle this file, and for doing it I write in the terminal the following code shufl file1.dat > shuffle.dat. Then I want to count how many times the order of two consecutive number from file1.dat have been modified in the shuffle.dat. I used the code

awk -F, 'FNR==NR{o[NR]=$0;next;}{v[$0]=FNR;n=FNR}
    END{ for(i=1;i<=n-1;i++) t+=v[o[i]]>v[o[i+1]]?1:0;
            print t;
    }' file.dat shuffle.dat

I must repeat this operations 10,000 times and collect the results in the file result.dat. Obviously doing it by terminal is not thinkable for time reasons. It’s possible to write an awk script to make it repeat 10,000 times the operations and write the results in the output file result.dat ? If yes how and how I can run the script by terminal ?

Cet article est repris du site http://stackoverflow.com/questions/...

Sites favoris Tous les sites

84 sites référencés dans ce secteur