http://www.perlmonks.org?node_id=1185363

Sonya777 has asked for the wisdom of the Perl Monks concerning the following question:

Hi experts,

I need help with an edit of a .txt file. I want to replace a part of the string with an empty space (i.e. remove the part of the string).

I have many lines like this one:

[{"absoluteLimits":{"conditionalLimits":[{"bidirVolume":4096000,"name" +:"Home"}],"resetPeriod":{"volume":"monthly day 15 00:??"}},"sliceVolu +me":5120,"subscriptionDate":"29-09-2016"},<b>{"absoluteLimits":{"cond +itionalLimits":[{"bidirVolume":102400000,"name":"Home"}],"resetPeriod +":{"volume":"2400 hours"}},"description":"Promotion_tariffbasic:29-09 +-2016,08-01-2017T10:21","name":"1004","sliceVolume":5120,"subscriptio +nDate":"30-09-2016T09:21"}]}

And from this line I want to remove the bolded string. To do this for many lines, basically I need to remove a part of the string that starts with:

{"absoluteLimits":{"conditionalLimits":[{"bidirVolume":102400000,"name +":"Home"}],"resetPeriod":{"volume":"2400 hours"}},"description":"Prom +otion_tariffbasic:

(this is the "common" part for each line, since the date is different for each line)

The problem is that the string contains special characters like ",:,} and a simple search & replace script does not work:

perl -p -e 's/{"absoluteLimits":{"conditionalLimits":[{"bidirVolume":1 +02400000,"name":"Home"}],"resetPeriod":{"volume":"2400 hours"}},"desc +ription":"Promotion_tariffbasic:.*//s' example.txt

Do you have any idea how this can be done?

Thanks a lot!

Sonya