prom in deleting a pattern

hi guys,
i have a directory.inside that so many directories and files are there.i want to search the complete directory for a pattern in all the .txt files.if i will find that pattern then i want to delete that pattern from that file.
please help me out.
i want it urgent

for file in `find $path -name "*.txt" -print`
do
sed "s/$pattern//g" $file > temp; mv temp $file;
done

hai anchal
when i am executing this shell script it is saying that
mv: target `./*.txt' is not a directory
what is the problem
i am not getting
actually in my file i have to replace ^M with spaces.
sp what change i have to make over here
plz replay me ASAP
THANK U

That error message doesn't make sense. What does find $path -name "*.txt" -print | less print for you (and did you remember to set path to something useful)?

The replacement is probably better done with tr -- if yours doesn't understand '\015' then try typing a real control-M there (might need to type ctrl-V ctrl-M to actually get one).

find $path -name "*.txt" -print" |
while read file; do
  tr '\015' ' ' <"$file" >"$file".tmp && mv "$file".tmp "$file"
done

hai
i have done like this
find $suvendu -name "*.txt" -print" |
while read file; do
tr '^M' ' ' <"$file" >"$file".tmp && mv "$file".tmp "$file"
done

but here again some problem is coming
like-
shell1.sh: line 3: unexpected EOF while looking for matching `"'
shell1.sh: line 5: syntax error: unexpected end of file
so whats the problem can u tell me
plz tell me ASAP

remove incomplete " after -print.

but it is not working yarr
i dont know why
i have done like this
for file in `find . -name "*.txt" -print`
do
sed "s/^M//g" $file > temp; mv temp $file;
done
~
it is executing succesfully
but it is not changing anything
inside the .txt file
so plz give me the solution ASAP

if u are not using any shell variable inside the sed syntex.. thn use single quotes instead of double with in the sed. hope it 'll work

sed 's/^M//g' $file

for file in `find . -name "*.txt" -print`
do
sed "s/suvendu/anil /g" $file > temp; mv temp $file;
done
~

when i am replacing suvendu with anil it is working
but when i want replace it from ^M to ' ' it is not working
so i dcontknow whats the problem in this

for file in `find . -name "*.txt" -print`
do
sed 's/^M// g' $file > temp; mv temp $file;
done
~
i have done like this
but again it is not working yarr

post the error msg...
also post any sample file

no eroor message is theer
it is executing successfully
but no change in the file ok

..................CPR AIRBUS NEW TECHNO ^M 000809786
..................CPR AIRBUS NEW TECHNO ^M 000809787
..................CPR AIRBUS NEW TECHNO ^M 000809788
..................CPR AIRBUS NEW TECHNO ^M 000809789
..................CPR AIRBUS NEW TECHNO ^M 000809790
like this it is there
in all the .txt files
but when i am executing the script no error is there
but after that no change in the file also
ok
so just check out this thing

try this

for file in `find . -name "*.txt" -print`
do
sed 's/\^M// g' $file > temp; mv temp $file;
done

it 'll work

It's not clear whether the files and/or your command lines contain the two characters "^" and "M" or real actual carriage returns (ASCII 13). My uninformed guess is you are mixing these up.

It's also possible that your sed cannot cope with literal carriage returns. Try tr again in that case. If you cannot get tr to accept either '\015' (that's octal for 13) or a literal ctrl-M, you will need some heavier workaround.

Actually here's one.

find . -name '*.txt' -print | xargs -n 1 perl -i -pe 'y/\015/ /'

Actually the "xargs -n 1" can be just "xargs". I started with a slightly different battle plan and forgot to take that out when I changed my mind.

can't you use the "dos2unix" command?

User Commands                                         dos2unix(1)

NAME
     dos2unix - convert text file from DOS format to ISO format

SYNOPSIS
     dos2unix [-ascii] [-iso] [-7] [-437 | -850 | -860 |  -863  |
     -865]  originalfile convertedfile

DESCRIPTION
     The dos2unix utility converts characters in the DOS extended
     character set to the corresponding ISO standard characters.

greets,
DN2

suvendu4urs wants to replace the CRs with spaces, not delete them.

i missed that part...

hai anchal
i got the solution u r slastone is correct
thanks a lot for u r answer