Weblog entry #2 for muondude

Some Random Perl Tips
Posted by muondude on Thu 22 Sep 2005 at 04:17
Tags: none.
Some handy command line scripts that I have often found useful.
Search for files with extension .tex starting in current directory and
below, print result to stdout, which then get passed to script; 
./bin/test.sh (just a dummy script I created to print the filename out):

  find . -path '*.tex' -print -exec ./bin/test.sh {} \;


Command Line file renaming: rename a group of files with extension .html to .shtml extensions:

 perl -e 'for (@ARGV) { ($new=$_) =~ s/(.+)(.)\.html$/$1$2.shtml/; rename $_, $new unless -e $new }' *.html

Convert a bunch of file names from UPPER case to lower case

 perl -e 'for (@ARGV) { ($new=$_) =~ tr/[A-Z]/[a-z]/; rename $_, $new unless -e $new }' *.html

Command line file editing:

  perl -p -i -e 's/\.html/\.shtml/g' j*.shtml

  perl -p -i -e 's/VLINK="\#FF0066"/VLINK="\#009900"/g' *.shtml

list lines with specified text (kinda like grep):

  perl -n -e 'print if /VLINK="\#FF0066"/;' *.shtml

Edit the file in place and make a backkup copy with extension .orig
this one line command replaces the Mac newline with a Unix newline:

  perl -p -i.orig -e 's/\r/\n/g' testfile.txt

 

User Login

Username:

Password:

[ Advanced Login ]

Register Account

Quick Site Search