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


In reply to Replace a string that contains special characters by Sonya777

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.