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 after print
  • -n process input line line
  • split splits input line on whitespace
  • shuffle (from list::util) shuffles list randomly
  • join " " creates 1 string list, putting space between members.

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -