Craig Sharp 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.
Assuming the first two fields are numeric: use strict; my @lines = ('20011219 074645 b03 3524 switch 10.3.xxx.xxx 3', '20011206 175228 b50 suite-Y switch-A 10.50.xxx.xxx 1'); foreach (@lines) { print "old: $_\n"; s/^(\d+\s+\d+\s+[^\s+]+)\s+([^\s+]+)\s+/$1-$2-/; print "new: $_\n"; } __END__ Result: old: 20011219 074645 b03 3524 switch 10.3.xxx.xxx 3 new: 20011219 074645 b03-3524-switch 10.3.xxx.xxx 3 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 -- ,-/- __ _ _ $Bill Luebkert ICQ=14439852 (_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED] / ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl) -/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/ _______________________________________________ Perl-Unix-Users mailing list. To unsubscribe go to http://listserv.ActiveState.com/mailman/subscribe/perl-unix-users