Error "Cat Error: Bad Address "

Hi
I get an Error when i am trying to edit a file thru shell script.

ERROR IS "cat: write error: Bad address."

I don't get this error everytime i run the shell script.
Any idea ??

Here is the piece of code:

echo "Attempting to edit ${ProbeRuleFile}"
if [ -f ${ProbeRuleFile} ]
then
cp ${ProbeRuleFile} ${ProbeRuleFile}.${datestamp}
sleep 5

    INSERT13="include \\"\\/opt\\/Omnibus\\/probes\\/solaris2\\/mform_fdf.rules\\"!!\#!\# Here we temporarily

set @Agent, for the above cases"
cat ${ProbeRuleFile} | sed "s/# Here we temporarily.*/${INSERT13}/" | tr '!' '\n' > ${ProbeRuleF
ile}

    echo "Setting Events Agent"
    sleep 5
    INSERT14="case \\"formation\\":!                 @Agent = \\$agent!               case \\"unix\\":"
    cat $\{ProbeRuleFile\} | sed "s/case \\"unix\\":.*/$\{INSERT14\}/" | tr '!' '\\n' > $\{ProbeRuleFile\}

    TEMP\_LINE_NU=\`grep -n "Details, \\"\\[0-9\\]" $\{ProbeRuleFile\} | awk -F: '\{print $1\}'\`
    \(\(TEMP\_LINE_NU = $TEMP\_LINE_NU \+ 1\)\)

echo "line no. ${TEMP_LINE_NU}"
cat ${ProbeRuleFile} | sed "${TEMP_LINE_NU}s/discard/\#discard/" | tr '!' '\n' > ${ProbeRuleFile
}
echo "done \n"
else
echo "File: ${ProbeRuleFile} not found!!!"
#exit
fi

Looks to me (at a glance) like it might have something to do with the way you are manipulating the file then directing it to it's own name.

cat ${ProbeRuleFile} | sed "s/# Here we temporarily.*/${INSERT13}/" | tr '!' '\n' > ${ProbeRuleFile}

Try this line of code by itself - and see what happens. You'll probably end up with an empty file of ${ProbeRuleFile}

This could then ruin the subsequent commands that use this file.

If you want to edit a file (as you are doing with the sed commands) you must rename the file to something else - then you can rename if back to the original.

To verify where the error is occuring - try bits of the script at a time i.e. comment out or remove subsequent steps. Or try the commands directly outside of the script (replacing the variables with the actual names).