PERL or AWK One-Liners

PERL
    If used in a script, NOT at the command line, change the ' to ".
    It will NOT work with single ticks(') in a script ONLY double (")!!!!
     
  1. Split a file every other line
    perl -ne 'print if (++$x)%2' file1 > file2
  2. Connect each pair of lines together perl -pe 'if ($. %2){ chomp }else{ s/^/ = / }' file
  3. perl -pi.bak -e 'tr/A-Z/a-z/' <filename>
    changes all letters to lowercase in <filename> AND
    saves the original as <filename>.bak
     
  4. perl -pi.bak -e 's/<original string>/<replacement string>/' <filename1> ... <filenamen>
    changes all the <original string> to <replacement string> IN the
    files <filename1> ... <filenamen> AND
    saves the originals with a .bak extention
     
  5. perl -e "print join(\"\n\", @INC);"
    Reports what is in the include path
     
  6. Add whitespace (pad) every line in a file
    #!/usr/bin/perl
    if ( $#ARGV != 1 ) {
      print "USAGE: </usr/local/bin/>AddTrailingWS.pl <filename> <line length>\n";
    } else {
      $filename = $ARGV[0];
      $maxline  = $ARGV[1];
      system ("mv $filename $filename.BAK");
      open (infile, "$filename.BAK");
      open (outfile,"> $filename");
      while (<infile>) {
        chop;
        $linelen = length;
        $addto   = $maxline-$linelen;
        if ( $linelen >= $maxline ) {
          print outfile "$_\n";
        } else {
          print outfile "$_";
          for ( 1..$addto ) {
            print outfile " ";
          }
            print outfile "\n";
        }
      }
      close(infile);
      close(outfile);
    }
AWK