################################################### ## ## WEB DEVELOPMENT HELPERS ## ################################################### #### REMOVING BINARY CHARACTERS # Binary characters do NOT belong in a webpage. # In some cases, they may screw up HTML rendering # Otherwise, they may make it difficult to run maintenance scripts against them # So binary characters should be removed first, before using other maintenance tools dos2unix is very helpful. It converts files in place from windows carriage returns to unix carriage returns. but it does NOT always work. If the file contains other binary characters, for example. But dos2unix is STILL helpful then because in its error, it will identify the line number and binary character that it first encounters. dos2unix filename.html or dos2unix * If you have identified a file with "null" characters: sed -i 's/\x0//g' filename.html or sed -i 's/\x0//g' * Where are the hat-ems (^M)? grep -c "^M" * |grep -v :0 (seee how to create ^M below) replace hat-em with normal carriage return perl -i -pe 's/^M/\n/g' filename.html or perl -i -pe 's/^M/\n/g' * In order to create that "hat-em" character you will need to use: control-V control-m or control-v and then m ____________________ #### PERMISSIONS FOR WEBPAGES * This may differ according to your host For static webpages, you MAY be able to use rw-r--r-- that is: read-write for root, and read for group and world chmod 644 filename.html or chmod 644 * If this doesn't work on YOUR HOST, use the scripting set up below. For webpages with pieces of script in them, you will need: rwxr-xr-x that is: read-write-execute for root, and read-execute for group and world chmod 755 filename.html or chmod 755 * ____________________ #### BATCH RENAMING If you have run a script and now you have a bunch of files with an extension that needs to be changed to the original filename... After moving your originals to a safe place, run this command: # rename files from .original to perl -e 'while(<*.original>){$_=~/(.*)\.original/; rename$_,$1}' #### BATCH STRING SUBSTITUTION perl -i -pe 's/panel1.html/panel2.html/g' * CHANGING A STRING in MULTIPLE TEXT FILES IN DIRECTORY For all files in this directory, change internal variable $REPLACEMENT to $REPLACEMENT ALSO rename the original files to .original perl -i.original -pe 's/\$REPLACEMENT/\$REPLACEMENT/g' * Same as above but without retaining the original files: perl -i -pe 's/\$REPLACEMENT/\$REPLACMENT/g' * The -p means to enclose your Perl program in a print loop that looks SOMEWHAT like this: while ($_ = <>) { print "$_"; }