#!/bin/sh
# 		move files
# Usage:
# xfiles command filekey (execute command on files greped by filekey.
# xfiles command filekey1 filekey2 (execute command 
#	on files greped by a filekey1 and those
#	with a filekey1 replaced by filekey2
# Example: xfiles mv .c .c.old
# Bug: Proven to work only in the current directory
#
ls *$2* | if test $3 
then awk ' { print $0 " " $0 } ' > /tmp/$$.xfiles
ed /tmp/$$.xfiles <<+
1,\$s/$2/xxyyzz/
w
1,\$s/$2/$3/
w
1,\$s/xxyyzz/$2/
w
1,\$s/^/$1 /
w
+
else cat > /tmp/$$.xfiles
ed /tmp/$$.xfiles <<+
1,\$s/^/$1 /
w
+
fi
cat /tmp/$$.xfiles 
sh /tmp/$$.xfiles 
