Search replace strings between single quotes in a text file

Hi There...
I need to serach and replace a strings in a text file.
My file has; books.amazon='Let me read' and the output needed is
books.amazon=NONFOUND

pls if anybody know this can be done in script sed or awk.. i have a list of different strings to be repced by NONFOUND.

any help would be appreciated!!

Thanks
hiano

sed "s/'[^']*'/NOTFOUND/g" infile

HI radoulov,

thanks for the quickest reply...
I tried that but no luck...the file generaeted is blank. :frowning:

cat test.txt | \
sed -e "s/'[^']*'/NOTFOUND/g" >test.txt

I need to update the same file with the new string. pls help

use it like this..

sed -i "s/'[^']*'/NOTFOUND/g" infile
1 Like
perl -i.bck -pe"
  s/'.*?'/NOTFOUND/g
  " infile
1 Like

thanks radoulov and itkamaraj!!!

I want to refine this search.. :slight_smile:

------
My file has; books.amazon='Let me read' and the output needed is

books.amazon=NONFOUND

------

Can I first find the text between string1= books.amazon=' and string2= ' (locate the text beween the cotes)

and then replace by NOTFOUND.!! this way i can replace multiple strings. I have tried this code but no luck..

sed -i 's/\(books.amazon='\)[^<]*\('\)/NOTFOUND/g' abc.txt

pls guide

cat books | sed 's/\(books.amazon=\)\(.*\)/\1NOTFOUND/'

books.amazon= is stored in \1
'Let me read' is stored in \2

Thanks MaskofZorro!!

Its working fine...except its failing for multiple similar strings.
If two similar strings are found, its only relacing first occurance. and deleting the rest.

Pls help.