[PLUG] SED Help Needed -- UPDATE

Michael Rasmussen michael at jamhome.us
Tue Feb 22 02:46:19 UTC 2011


On Mon, Feb 21, 2011 at 05:12:21PM -0800, Michael Rasmussen wrote:
> On Mon, Feb 21, 2011 at 04:15:56PM -0800, Rich Shepard wrote:
> > On Mon, 21 Feb 2011, Rich Shepard wrote:
> > 
> > >   In English, I want to locate one or more digits followed by a comma and
> > > one or more digits, then replace only the comma with a pipe.  What I've
> > > tried include:
> > > 	s/.*[0-9],[[0-9]/\&|/g
>  
> First, since your're interested in <DIGIT>,<DIGIT> why match anything else?
> 
> Second, I don't do sed, so here's how it can be done in perl
> 
> 
> #!/usr/bin/perl
> 
> while(<DATA>) {
>     s/(\d),(?=\d)/$1|$2/g;
>     print;
> }
> 
> __DATA__
> work with 19,43  or so
> 14,99
> we have, at most, 14,23 to do though some say it is 18,44
> Without digits, all the , will remain.
> With digits 9, Ah ha! or
> With,3 no change for a 2nd line
> But again 3,4,5,6 all have bars.
> ^^^^^^^  produces vvvvvvvvvvvvvv
> work with 19|43  or so
> 14|99
> we have, at most, 14|23 to do though some say it is 18|44
> Without digits, all the , will remain.
> With digits 9, Ah ha! or
> With,3 no change for a 2nd line
> But again 3|4|5|6 all have bars.
> 
> Which I believe covers the cases you described. 
> Cut #!/usr/bin/perl through the line starting }
> remove the DATA text and you can run it on your data.
 

And after a bit of poking around I now know a little bit more about perl.
Change that to:
#!/usr/bin/perl

while(<DATA>) {
    s/(\d),(?=\d)/$1|/g;
    print;
}


-- 
      Michael Rasmussen, Portland Oregon  
  Trading kilograms for kilometers since 2003
    Be appropriate && Follow your curiosity
          http://www.jamhome.us/
The Fortune Cookie Fortune today is:
Cycle tracks will abound in Utopia.
	~  H.G. Wells



More information about the PLUG mailing list