If you can be sure the regex won't match any other field, you can try:

perl -p -i -e 's/\b0(\d{10})\b/\+91$1/g;' filename

If there are other fields that it could match and munge, then it could all go horribly wrong and you're better off with something that accurately replaces only that field, like Tux already posted.

Update: I just took a look over at your thread at SO. You're trying a dangerous thing by counting commas in a CSV. Any element of a CSV can have commas inside of quotes to protect them, so you could have any number of commas before the 35th element in a row. CSV is a deceptive format-- it seems all simple and benign, but can be complicated in really annoying ways. If the quick and dirty regex won't work, use a module like Tux shows that is designed to deal with the unexpected but legal cases in the CSV.


In reply to Re^2: edit a CSV and "in-place" replacement by bitingduck
in thread edit a CSV and "in-place" replacement by slayedbylucifer

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.