<commit_before>Perl-one-liners
======

Collection of tricks of Perl one-liners

Print hello world

    perl -e 'print "Hello world!\n"'
    perl -le 'print qq/Hello world!/'

Grep-like pattern searcher

    cat input.txt | perl -ne 'print if /regex/'
    seq 1 100 | perl -ne 'print if /^9/'
    seq 1 100 | perl -ne 'print if /9$/'

Sed-like string replacement

    cat input.txt | perl -pe 's/old/new/'
    seq 1 10 | perl -pe 's/1/one/'

Exchange first and second column

    cat input.txt | perl -alne 'print "$F[1]\t$F[0]"'
    seq 1 10 | paste - - | perl -alne 'print "$F[1]\t$F[0]"'
    seq 1 10 | paste - - | perl -alne 'print join("\t", @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join(chr(9), @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join(chr 9, @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join chr 9, @F[1,0]'

Print the length of each line

    cat input.txt | perl -lne 'print length($_)'
    seq 1 10 | perl -lne 'print length($_)'

Split a text file into characters and count the number of them

    cat input.txt | perl -pe 's//\n/g' | sort | uniq -c
    seq 1 10 | perl -pe 's//\n/g' | sort | uniq -c

Print the sum of a list of numbers

    seq 1 100 | perl -lne '$sum += $_; END{print $sum}'
    seq 1 100 | perl -lne 'BEGIN {print qq/Sum: /} $sum += $_; END{print $sum}'
    seq 1 100 | perl -ne 'BEGIN {print qq/Sum: /} $sum += $_; END{print "$sum\n"}'
    seq 1 100 | perl -nE 'BEGIN {print qq/Sum: /} $sum += $_; END{say $sum}'

Min, max, sum, mean of a list of number using [datamash](http://www.gnu.org/software/datamash/)

    seq 1 100 | datamash --header-out min 1 max 1 sum 1 mean 1
<commit_msg>get min, max and sum of a list of numbers using List::Util<commit_after>Perl-one-liners
======

Collection of tricks of Perl one-liners

Print hello world

    perl -e 'print "Hello world!\n"'
    perl -le 'print qq/Hello world!/'

Grep-like pattern searcher

    cat input.txt | perl -ne 'print if /regex/'
    seq 1 100 | perl -ne 'print if /^9/'
    seq 1 100 | perl -ne 'print if /9$/'

Sed-like string replacement

    cat input.txt | perl -pe 's/old/new/'
    seq 1 10 | perl -pe 's/1/one/'

Exchange first and second column

    cat input.txt | perl -alne 'print "$F[1]\t$F[0]"'
    seq 1 10 | paste - - | perl -alne 'print "$F[1]\t$F[0]"'
    seq 1 10 | paste - - | perl -alne 'print join("\t", @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join(chr(9), @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join(chr 9, @F[1,0])'
    seq 1 10 | paste - - | perl -alne 'print join chr 9, @F[1,0]'

Print the length of each line

    cat input.txt | perl -lne 'print length($_)'
    seq 1 10 | perl -lne 'print length($_)'

Split a text file into characters and count the number of them

    cat input.txt | perl -pe 's//\n/g' | sort | uniq -c
    seq 1 10 | perl -pe 's//\n/g' | sort | uniq -c

Print the sum of a list of numbers

    seq 1 100 | perl -lne '$sum += $_; END{print $sum}'
    seq 1 100 | perl -lne 'BEGIN {print qq/Sum: /} $sum += $_; END{print $sum}'
    seq 1 100 | perl -ne 'BEGIN {print qq/Sum: /} $sum += $_; END{print "$sum\n"}'
    seq 1 100 | perl -nE 'BEGIN {print qq/Sum: /} $sum += $_; END{say $sum}'

Min, max, sum, mean of a list of number using List::Util and [datamash](http://www.gnu.org/software/datamash/)

    seq 1 100 | perl -MList::Util=min,max,sum -lne 'push @s, $_;END{print join qq/\t/, min(@s),max(@s),sum(@s)}'
    seq 1 100 | datamash --header-out min 1 max 1 sum 1 mean 1

{'fraction_non_alphanumeric': 0.1677640996278271, 'fraction_numerical': 0.04351560263383911, 'mean_word_length': 2.501002004008016, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900199', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1347, 'n_words': 503}