Skip to content

Instantly share code, notes, and snippets.

@kirkins
Last active April 1, 2017 03:11
Show Gist options
  • Save kirkins/4f7963abfd39e7a96334991be7df215a to your computer and use it in GitHub Desktop.
Save kirkins/4f7963abfd39e7a96334991be7df215a to your computer and use it in GitHub Desktop.
# LINKS:
* http://www.math.harvard.edu/computing/perl/oneliners.txt
* https://gist.github.com/mischapeters/1e8eef09a0aafd4f24f0
# random line from file
perl -e 'srand;' -e 'rand($.) < 1 && ($it = $_) while <>;' -e 'print $it' file.csv
#NOTE: the above is easier with the following bash command
shuf -n 1 file.csv
# CSV get all in column 'n', n is 0 in example
perl -n -a -F, -e 'print "$F[0]\n"' file.csv
# mass rename for files, aaa to bbb in example
ls | perl -ne 'chomp; next unless -e; $o = $_; s/aaa/bbb/; next if -e; rename $o, $_';
# replace term in multiple files
perl -pi -e 's/aaa/red/g' *
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment