sorting - How to Randomize Columns of a Text File in Linux -
i take text file , each line randomize words/columns. files contain millions of rows, efficiency important. i've tried google route, find related sorting lines randomly , not columns.
for example taking simple file (i'll use numbers, words):
111 222 333 444 555 555 666 777 888 999 000 000 333 555 777
the output might following:
222 111 555 444 333 777 555 666 000 999 888 777 333 000 555
perl rescue:
perl -mlist::util=shuffle -lne 'print join " ", shuffle split' < input.txt > output.txt
-l
appends newline afterprint
-n
process input line linesplit
splits input line on whitespaceshuffle
(from list::util) shuffles list randomlyjoin " "
creates 1 string list, putting space between members.
Comments
Post a Comment