How to count the number of times a single character is present in each line of a file
Let's suppose we have a text file named "file.csv" and want to count for each line the number of times a character is displayed, such as the character ",".
Suppose the result is the output of the same file "file.csv" preceded in each line by the count itself.
Just simply the following single line perl:(more…)
Rename a group of files based on a regex
Just print line 25 of a file
Encode/decode a file or string in Mime Base64
Suppose you have a "test encode" string and a "prova.txt" file you want to encode in Mime base64. To solve the problem we can simply launch the command line:
perl -MMIME::Base64 -e 'print encode_base64("test encode")' perl -MMIME::Base64 -0777 -ne 'print encode_base64($_)' prova.txt
Number a text file
Add 1 to all numbers on a string
$str =~ s/(\d+)/$1+1/ge