Skip to content

Instantly share code, notes, and snippets.

@universome
Last active March 17, 2018 11:20
Show Gist options
  • Save universome/8cb22000c8c7a0408eea to your computer and use it in GitHub Desktop.
Save universome/8cb22000c8c7a0408eea to your computer and use it in GitHub Desktop.
Shuffle contents of a csv file without breaking headers
sed -n '1!p' data.csv | perl -MList::Util=shuffle -e 'print shuffle(<STDIN>);' > shuffled.csv
head -1 data.csv >> tmp & cat shuffled.csv >> tmp
mv tmp shuffled.csv
# You can also use "awk 'NR>1' data.csv", but it will be slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment