King David
King David

Reputation: 540

perl + delete the line only if match the exactly string in line

I work on the following file:

more file1


name="UAT/CC/Global/MES/UK/adWerum-UK" 
name="UAT/CC/Global/MES/UK/adWerum-UK-Adapter" 
name="UAT/CC/Global/MES/UK/adWerum-UK1" 
name="HOME/UAT/CC/Global/ME/UK/adWerum-UK" 

I created the following perl command in order to delete only exactly string with backslashes

UAT/CC/Global/ME/UK/adWerum-UK

the perl syntax:

perl -n -i -e 'print unless m/\Q$ENV{A}\E/' file1

the problem is perl removing all lines that contain the line:

UAT/CC/Global/ME/UK/adWerum-UK    

example

A=UAT/CC/Global/MES/UK/adWerum-UK
export A=UAT/CC/Global/ME/UK/adWerum-UK
perl -n -i -e 'print unless m/\Q$ENV{A}\E/' file1

.

more file1

file is empty

While the expected results are

name="UAT/CC/Global/MES/UK/adWerum-UK-Adapter" 
name="UAT/CC/Global/MES/UK/adWerum-UK1" 
name="HOME/UAT/CC/Global/ME/UK/adWerum-UK" 

please advise what need to change in my perl syntax in order to remove only the line with the match string between the double quota

Upvotes: 1

Views: 260

Answers (1)

Borodin
Borodin

Reputation: 126762

Why don't you just include the double quotes in the regex pattern?

perl -i -ne 'print unless /"\Q$ENV{A}\E"/' file1

Upvotes: 1

Related Questions