Obviously you can use a one line sed program to do what you want
sed -e "s/YOUR_ORIG_PATTERN/SUBSTITUTE_PATTERN/" INPUT_FILE > OUTPUT_FILE
cat OUTPUT_FILE > INPUT_FILE
But I thought you might like to see how clever you can be with awk grep and sed
This is part of of script for replacing lines in a recipe application using Runtime Revolution for the GUI bit and the shell for information processing, soon to be published on my page at Cool Solutions, but it shows the method.
These scripts are naive as they are meant for naive newbies
#!/bin/bash
#edrnote.sh indexno lineno newline type
#replace lineno for indexno in notes.txt with newline
NOTEFILE="$HOME/cookbook/book/notes.txt"
CTMP="$HOME/cookbook"
if [ $1 -lt 1 ]
then
exit
fi
INDEX=$1
LINENO=$2
NLINE="$3"
TYPE=$4
if [ $TYPE -lt 1 ]
then
#This is a modification line
#First select all the notes for this recipe index
#to find out which line to replace
awk -v IDX="$INDEX" 'BEGIN{RS = "#"}{if(NR == IDX){print $0}}' $NOTEFILE |\
awk '{if(length() > 3) print $0}'|\
awk -v LINNO="$2" '{if(NR == LINNO) print $0}' > $CTMP/thisone.txt
CLINE=`cat $CTMP/thisone.txt`
if [ ${#CLINE} -lt 1 ]
then
echo "Couldn't find line $2"
exit
fi
#Now we find the line number in the original file
CLINNO=`grep -n -E "$CLINE" $NOTEFILE | awk -F":" '{print $1}'`
#We use sed to insert the new line then delete the old line
cp $NOTEFILE $CTMP/newnotes.txt
sed -e "$CLINNO"i"$NLINE" -e "$CLINNO"d $CTMP/newnotes.txt > $CTMP/notes.txt
fi
You can find a lot more scripts at this level on my pages at
http://www.novell.com/coolsolutions/author/1211.html