0

I need to randomise a csv datafile using AWK/ BASH. i.e shuffle each line in the file. The incremented line numbers in field 1 are not present in my real data file. I have included that to demonstrate the After data set. Any suggestions on how to achieve that would be greatly welcomed.

Before:

1, asdasd,34534,sdfsdf,456,sdsdfsd,36345,asdaa
2, ghjghj,34534,ert,3456345,sdsdfsd,36345,asdaa
3, 34123,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
4, dfg,34534,ghjhj,45645,sdsdfsd,36345,asdaa
5, 34123,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
6, xcv,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
7, 34123,xcv,sdfsdf,3456345,dfgdfgdfgdfg,36345,asdaa
8, 34123,34534,sdfsdf,456456,sdsdfsd,36345,asdaa
9, fgdf,34534,sdfsdf,3456345,sdsdfsd,36345,dfgdfg
10, 34123,34534,sdfsdf,vbnvb,vbnbnvb,36345,asdaa

After:

1, asdasd,34534,sdfsdf,456,sdsdfsd,36345,asdaa
10, 34123,34534,sdfsdf,vbnvb,vbnbnvb,36345,asdaa
3, 34123,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
4, dfg,34534,ghjhj,45645,sdsdfsd,36345,asdaa
5, 34123,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
9, fgdf,34534,sdfsdf,3456345,sdsdfsd,36345,dfgdfg
7, 34123,xcv,sdfsdf,3456345,dfgdfgdfgdfg,36345,asdaa
6, xcv,34534,sdfsdf,3456345,sdsdfsd,36345,asdaa
8, 34123,34534,sdfsdf,456456,sdsdfsd,36345,asdaa
2, ghjghj,34534,ert,3456345,sdsdfsd,36345,asdaa     
Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
user1654528
  • 395
  • 3
  • 12
  • 1
    newer versions of `sort` can randomize data. Check `man sort`. I don't recall the exact `--option` (but my recollection it might be `--shuf(fle)`. Good luck. – shellter Dec 24 '15 at 18:36
  • ...could also be a duplicate of http://stackoverflow.com/questions/2153882/how-can-i-shuffle-the-lines-of-a-text-file-on-the-unix-command-line-or-in-a-shel, or http://stackoverflow.com/questions/886237/how-can-i-randomize-the-lines-in-a-file-using-standard-tools-on-red-hat-linux, or http://stackoverflow.com/questions/286640/how-can-i-print-the-lines-in-stdin-in-random-order-in-perl]. Did you search for duplicates at all? – Charles Duffy Dec 24 '15 at 18:39
  • Thanks the duplicate is what I require – user1654528 Dec 24 '15 at 18:41

0 Answers0