Number a text file

Suppose we have a text file (prova.txt) that we want to number. We can use:

perl -pe '$_ = "$. $_"' prova.txt

If you want to simulate the output of cat -n prova.txt just use:

perl -ne 'printf "% 5d %s", $., $_' prova.tx

To remove the numbering we can use:

perl -pe 's/^\s*\d+\s*//' prova.txt