Bash one liner to randomize lines in file

Discussion in 'Mac Programming' started by eshroom, Mar 11, 2010.

  1. eshroom macrumors 6502

    Joined:
    Oct 18, 2006
    #1
    I got it from this website and it goes something like this:

    for i in `cat unusual.txt`; do echo “$RANDOM $i”; done | sort | sed -r ’s/^[0-9]+ //’ > randorder.txt

    This is for Linux, but no matter how I alter it I can't get it to work in terminal... Any ideas?

    I changed -r to -e and get error message: "sed: 1: "’s/^[0-9]+\n": invalid command code ?"

    Thanks
     
  2. eshroom thread starter macrumors 6502

    Joined:
    Oct 18, 2006
    #2
    SOLVED

    Thank you to SirDice at MacOSXHints, the answer is:

    for i in `cat unusual.txt`; do echo "$RANDOM $i"; done | sort | sed -E 's/^[0-9]+ //' > randorder.txt

    I should have capitalised the -e
     
  3. nephilim7 macrumors regular

    Joined:
    Jun 13, 2008
  4. jpyc7 macrumors 6502

    Joined:
    Mar 8, 2009
    Location:
    Denver, CO
    #4
    Standardization of command-line options between different OSes would be good too.
     

Share This Page