Hi, Monks!

I have a problem that I've come up with a reasonably nice solution for, but have been going over it in my head and wondering if it's the best solution.

I have a log file in which I want to hide file and path names. I want to preserve the appearance of a directory structure, so I do not want to hide the "/" characters that are used as directory separators.

The filename will always appear at most once per line, and will always appear inside of an easily identifiable section, like this: file="path/goes/here".

I would like to process that example so that the output looks like this: file="xxxx/xxxx/xxxx".

The solution that I came up with does exactly what I want. From the command line, I pipe it to this (this is on a Unix host):

... | perl -pe '1 while s|(file="[x/]*)[^x/"]|$1x|;'
I've been wondering if there is something simpler, like somehow being able to do s|[^/]|x|g on the text between file=" and ", but I haven't been able to figure out how.

Does anyone have any suggestions?


In reply to Selectively replacing characters inside a string by markkawika

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.