Charles Farinella wrote:
> 
> On Tue, 15 Feb 2000, Michael O'Donnell wrote:
> 
> >
> > Oooops - that last / character shouldn't be there.  And I
> > now realize I'm not sure what you wanted to do; that sed
> > command will rewrite instances of xx/yy/zz to be zz/yy/xx,
> > so mm/dd/yy would become yy/dd/mm.  If you instead wanted
> > mm/dd/yy to become yy/mm/dd the command would be:
> >
> > sed -e 's;\(..\)/\(..\)/\(..\);\3/\1/\2;' <originalFile >newFile
> >
> >
> > Sorry about that - I shot from the hip and only hit my toe...
> 
> I am happy to have whatever help I can get.  Thanks.
> 
> This kind of works.  I didn't explain well.
> 
> The file I have is set up as such:
> 
> id,mm/dd/yy/,text,$00.00
> 
> When I run the above sed command, it fixes the date, but not all of the id
> numbers are still separated by commas.  For example:
> 
> 1,98/3/16,misc,$100.00
> 299/,7/4,misc,$100.00
> etc., seemingly at random
> 
> As you can see, in record 2 the comma has been moved to the right of the
> first /.
> 
> I know nothing about sed, and it is not apparent to me how to correct
> this.
> 
> I'll come back to it later tonight.
> 
> Thanks to all.
> 

This is caused becuase the regular expression is searching for a
2 digit month (and all other fields for that matter).  Here is much
safer perl solution:

perl -pe 's#(\d{1,2})/(\d{1,2})/(\d{1,4})#$3/$2/$1#g' < infile > outfile

-Matt

-- 
Matthew W. Herbert   x75764
Spectrum Advanced Applications
http://www.aprisma.com/
mailto:[EMAIL PROTECTED]

**********************************************************
To unsubscribe from this list, send mail to
[EMAIL PROTECTED] with the following text in the
*body* (*not* the subject line) of the letter:
unsubscribe gnhlug
**********************************************************

Reply via email to