Perl One Liners

Manipulating files with convenient perl one line commands.

Learning Objectives

  • Familiarize yourself with manipulating files by using Perl one line commands.

Topics covered

Perl is a programming language that used to be very popular with system administrators. It predates Python. It has some very powerful regular expression abilities allowing you to easily do things on the commandline that woul otherwise thake many hours. Here ar some useful perl one line commands.

Strip trailing whitespace from a file

$ perl -lpe 's/\s*$//' FILENAME

Replace wrong quote

$ perl -i -p -e "s/’/'/g;"  *.md

Remove ^M from file

$ perl -p -i -e 's/\r\n$/\n/g'