Many oneliners rely on the magic of Perl's -i switch, which means when files supplied on the commandline are opened they are edited in place, and if an extension was passed, a backup copy with that extension will be made. -e specifies the Perl code to run. See perlrun(1) for any other switches used here - in particular, -n and -p make powerful allies for -i.
The unsurpassed power of Perl's RegularExpression flavour contributes a great deal to the usefulness of nearly every oneliner, so you will also want to read the perlretut(1) and perlre(1) manpages to learn about it.
perl -ni.bak -e'/\S/ && print' file1 file2
perl -00 -pi.bak -e1 file1 file2
Note the use of 1 as a no-op piece of Perl code. In this case, the -00 and -p switches already do all the work, so only a dummy needs to be supplied.
perl -e 'printf "%08b\n", $_ for unpack "C*", shift' 'My String'
cat $file | perl -ne 's/\\n/\012/g; s/\\t/\011/g; print'
You can use any punctuation as the separator in an s/// command, and if you have backslashes or even need literal slashes in your pattern then doing this can increase clarity.
This is useful if you suspect that ps(1) is not reliable, whether due to a RootKit or some other cause. It prints the process ID and command line of every running process on the system (except some "special" kernel processes that lie about/don't have command lines).
perl -0777 -pe 'BEGIN { chdir "/proc"; @ARGV = sort { $a <=> $b } glob("*/cmdline") }
$ARGV m!^(\d+)/!; print "$1\t"; s/\0/ /g; $_ . "\n";'
It runs an implicit loop over the /proc/*/cmdline files, by priming @ARGV with a list of files sorted numerically (which needs to be done explicitly using <=> -- the default sort is ASCIIbetical) and then employing the -p switch. -0777 forces files to be slurped wholesale. Per file, the digits that lead the filename are printed, followed by a tab. Since a null separates the arguments in these files, all of them are replaced by spaces to make the output printable. Finally, a newline is appended. The print call implicit in the -p switch then takes care of outputting the massaged command line.
4 pages link to PerlOneLiners: