Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2022-05-21 23:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (78 votes). Check out past polls.

    Notices?