randomize shuffling of a file with many lines
Hi all,
I have a file with many lines (600M),and i want to create permutation of each line, random permutation. input for example: first line: abcdef second line: abcdef and so on.. Possible output: first line: efdacb second line: afebcd any linux/perl/python solution will be helpfull! Thanks, Pap |
not really following but maybe this will help:
Code:
expr 600000 % $RANDOM |
If you wanted to just mix up lines in a file, 'shuf' would work, but it seems you want to mix up individual characters within a line.
Do you accept C code for an answer ? With that many lines you probably need it to be fast. |
Hi
PHP has a function called str_shuffle that does the job, but only for a line. Something like this should do it: PHP Code:
|
Alright, here it is in C, it was a bit of practice for me:
Code:
#include <stdio.h> Input: Code:
abcdef Code:
fdbace |
Thanks metaschima!!
I gave it a shoot, and it looks great!! |
You may want to adjust the maximum string size STRING_MAX as needed for long lines.
|
All times are GMT -5. The time now is 01:59 PM. |