Find and replace problem

i have a script that will find a certian pattern and replace it with blank space

#!/bin/ksh

for i in `cat test.txt | grep "UTILINET" | cut -c 172-191`
do
perl -pi -e 's/$i//g' test.txt
echo "Completed"
done

the command gives some of the below strings

50032E1B            
50020F8E            
90501D67            
50016FC2            
5000DC3F            
50016E5D            
5002C9C4            
50010DB0            
5002E085

when i m executing the script it is giving error as
./C.sh[3]: no space

Please help me out

Beyond the problem ,the logic behind ur script is not seems to be correct.

If you post you input and the output your expecting , you can expect more results.

Regards
Sastry.P

Is this what you're trying to do?

awk '/UTILINET/ {print substr($0, 1, 171) substr($0, 192)}' filename

The o/p from the for statement is always one like 50032E1B . So if you decode it in the script it should do the following

for i in 50032E1B
do
perl -pi -e 's/50032E1B//g' test.txt
echo "Completed"
done

Basicall my script is finding the pattren one by one and replacing it with a blankspace

 
perl -pi -e s/"$i"//g  file_name.txt

worked for me. By the way, no need of "cat" in the for loop, grep "string" file_name is enough.

i have now changed the script to below

#!/bin/ksh

while read i
do
perl -pi -e 's/'$i'//g' test.txt
echo "Completed"
done < /ednadtu3/u01/pipe/naveed/test/test.txt

But when i do command "cat test.txt | grep "UTILINET" | cut -c 172-191 | head -10" it shows the below strings


cat test.txt | grep "UTILINET" | cut -c 172-191 | head -10

            |       
            |       
            |       
            |       
            |       
            |       
            |       
            |       
            |       
            |    

Why these are coming it should be blankspace na ?