View Single Post

  #5 (permalink)  
Old 05-03-2008, 03:37 AM
meowing meowing is offline
Junior Member
User
 
Join Date: Feb 2007
Posts: 19
Rep Power: 0
meowing
Default

Let's see if I get this..
Code:
#!/bin/bash
DIR="$1"
if [ $# -eq 0 ]; then
	echo "$(basename $0) dir"
	exit 1
fi

for f in $DIR/*
do
	if [ ! -f $f.bakup ]; then
		/bin/cp $f $f.backup
	fi
	out="/tmp/out.$$.tmp
	cat $f | sed '/^$/d;s/^[ \t]*//;s/[ \t]*$//' > $out
	/bin/mv $out $f
done
You mean .bakup then would be .php and/or .html etc.?

I'd like to apply this to all .css, .js, .htm*, .php* files.

I used to have this with perl, but I lost the script, it was something like;

Code:
#!/bin/sh
$ perl -pi -e 's|[old_string]|[new_string]|g' [file]
but I don't really remember much of it. It could run entirely RegExp based.

Last edited by meowing; 05-03-2008 at 04:19 AM..
Reply With Quote