markkawika has asked for the wisdom of the Perl Monks concerning the following question:
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):
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.... | perl -pe '1 while s|(file="[x/]*)[^x/"]|$1x|;'
Does anyone have any suggestions?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Selectively replacing characters inside a string
by liverpole (Monsignor) on Jun 11, 2009 at 01:28 UTC | |
|
Re: Selectively replacing characters inside a string
by johngg (Canon) on Jun 11, 2009 at 10:46 UTC | |
by markkawika (Monk) on Jun 11, 2009 at 16:54 UTC | |
|
Re: Selectively replacing characters inside a string
by AnomalousMonk (Archbishop) on Jun 11, 2009 at 05:15 UTC | |
|
Re: Selectively replacing characters inside a string
by dsheroh (Monsignor) on Jun 11, 2009 at 09:57 UTC | |
by markkawika (Monk) on Jun 11, 2009 at 16:42 UTC |