REGEX help with substitute



Hello All,

I'm not so new to perl as I am to Regular Expressions and useing the s///;
substitute operator.

Where I am running into a problem is fixing a log file program that reads in
the log file and splits it on the spaces.

The program works fine untill I hit a user who somehow in the past managed
to get a username with a space in it.

I have no control over user accounts and I just have to just deal with it.

So far I have found 2 out of about 2000 users have this problem.

My current fix is to rewrite the entire log file. 238 lines of code to do
this to root out and correct the offending usernames.

I figured a easy fix would be to use substitute inline with my current code
and not have to rewrite the file like so:

substitute $firsthalf $secondhalf with $firsthalf_$secondhalf
or
$_ =~ s/($firsthalf) ($secondhalf)/($firsthalf)_($secondhalf)/g;

1st am I correct that variables have to be like this ($???)
2nd is my regular expression correct. I downloaded a program to test regular
expressions but it cannot handle variables in it.

I will deal with the fact that I may have another user with
$firsthalf_$secondhalf later by doing some checking prior to the
substitution.

Thanks in advance for any and all help,
Bill


.



Relevant Pages

  • Re: sed substitution of variable characters
    ... >> Is it possible to use sed to substitute for variable characters? ... apache's log file is not exactly my favorite reading material ... >> I know that I can do this with two sed statements but can it be done ...
    (comp.unix.shell)
  • sed substitution of variable characters
    ... Is it possible to use sed to substitute for variable characters? ... apache's log file is not exactly my favorite reading material ... Dave ...
    (comp.unix.shell)
  • Re: Constant file size
    ... unless you *really* want to rewrite the whole log file ... I suggest you roll over to different log files (deleting old ...
    (microsoft.public.dotnet.languages.csharp)