Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

eshroom

macrumors 6502
Original poster
Oct 18, 2006
292
4
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
 
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
 
Note: The above splits the input file by all whitespace, not just line breaks (so it only works if there's only one word per line).

Here's a modified version that works on full lines instead:

while read i; do echo "$RANDOM $i"; done < unusual.txt | sort | sed -E 's/^[0-9]+ //' > randorder.txt
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.