Well, looking at the pattern, it looks like you need to start your 
substitution when the pattern matches 'bNN' and ends when it hits an IP 
address, matching 'NN\.' or 'NNN\.'.

So, here's some (baby-talk ;)) code:

#!/usr/bin/perl

$line = "20011219 074645 b03 3524 switch 10.3.xxx.xxx 3";
# break it up into thirds....
# First third...
($firstThird) = ($line =~ /(\d+\s\d+\s)/);
# Second third (where the substitution will take place)
($secondThird) = ($line =~ /(b\d{2} .*)\s\d{2,3}\./);
# Final third...
($finalThird) = ($line =~ /(\s\d{2,3}\..*$)/);

# Do your substitution on the second third...
$secondThird =~ s/\s/-/g;

print "LINE (before): $line\n";

# Now put the pieces back together again
$line = $firstThird . $secondThird . $finalThird;

print "LINE (after): $line\n";

OUTPUT:

$ ./testmail.pl
LINE (before): 20011219 074645 b03 3524 switch 10.3.xxx.xxx 3
LINE (after): 20011219 074645 b03-3524-switch 10.3.xxx.xxx 3

Of course, there's TIMTOWTDI... :)

Jason

If memory serves me right, on Monday 07 January 2002 08:41, you wrote:
> Hi all,
>
> I have a file with lines that are in the following format:
>
> 20011219 074645 b03 3524 switch 10.3.xxx.xxx 3
>
> I need to do a substitution so that the line appears as:
>
> 20011219 074645 b03-3524-switch 10.3.xxx.xxx 3
>
> Note the inclusion of the dashes.
>
> Here is another example:
>
> Old:
> 20011206 175228 b50 suite-Y switch-A 10.50.xxx.xxx 1
>
> New
> 20011206 175228 b50-suite-Y-switch-A 10.50.xxx.xxx 1
>
> Again note the inclusion of the dashes.
>
> I cannot figure out the regexp to handle this problem and do the
> substitution of the spaces.
>
> Thanks,
>
> Craig A. Sharp
> Unix Systems Administrator
> DNS Administrator
> Roush Industries
> Office: 734-779-7282
> Cell: 734-231-6769
> Fax: 734-779-7807
> [EMAIL PROTECTED]
> ====================================================
> I have not lost my mind, it's backed up on tape somewhere!
> ====================================================
>
> _______________________________________________
> Perl-Unix-Users mailing list. To unsubscribe go to
> http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users
_______________________________________________
Perl-Unix-Users mailing list. To unsubscribe go to 
http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users

Reply via email to