View Single Post

  #4 (permalink)  
Old 05-03-2008, 02:40 AM
rockdalinux's Avatar
rockdalinux rockdalinux is offline
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 581
Rep Power: 7
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Here is a simple idea..

first backup existing file as .backup
Replace and update file

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
Try code in dummy setup; once okay; move to production.
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote