I have a file
love=/abc
day=abc
night=xyz
afternoon=xyzabc
I am reading each in value in a variable, now I need to replace the 2nd variable with a particular string. like
$1st = "/abc" $replace1 = "/abc/pqr"
$2nd = "abc" $replace2 = "abc1"
$3rd = "xyzabc" $replace3 = "mnpabc"
I used perl -0777 -pi -2 's%$1st%$replace1%' file
this does 1st line replacement
I used perl -0777 -pi -e 's/3rd/$replace1/ file
this does the 3rd line.
but the moment I replace $2nd with $replace , it replaces all places where ever there is "abc". how can I restrict this to replace only one element at a time?