John,

Assuming that you're addresses are in a file called address.txt then

$ sed 's/,,/ /g' address.txt

Would substitute all occurrence of two consecutive commas with a space. The s
means substitute, the g means all non-overlapping occurrences of the pattern,
not just the first one. I'm not an expert in this area either, but I don't
believe that you can use extended regular expression syntax, which, may be more
appropriate.

For example, you may want any number of consecutive commas greater than one to
be substituted with a space. In which case the regular expression would be

,{2,}

I don't believe that this is supported by sed. It is supported with egrep as in

$ egrep ',{2,}' address.txt
Name,Add,,City,State,Zip,Contact
Joe Inc,123 Main,,Brown,NY,12345,Joe

If you need to use the extended syntax (you don't know how many commas), then
you can do the same thing with awk.

$ awk '{sub(",{2,}", " ");} {print $0};' address.txt
Name,Add City,State,Zip,Contact
Joe Inc,123 Main Brown,NY,12345,Joe
Pete Inc,456 7th,PO Box 1,Green,NY,12346,Pete
Jack Inc,789 1st,Bldg 5,Red,NY,12347,Jack

Hope this helps,

Anthony






[EMAIL PROTECTED] on 05/08/2000 02:50:52 PM

To:   [EMAIL PROTECTED]
cc:    (bcc: Anthony Simon/THP)

Subject:  A sed question



To All,

I have what appeared to me to be a simple problem.
I went out and bought the sed & awk book (O'Reilly) and
went at it. About 7 or 8 hours later, I stopped going at it :-(

I have a simple CVS file that looks like this:

Name,Add,,City,State,Zip,Contact
Joe Inc,123 Main,,Brown,NY,12345,Joe
Pete Inc,456 7th,PO Box 1,Green,NY,12346,Pete
Jack Inc,789 1st,Bldg 5,Red,NY,12347,Jack

If you noticed, the 2nd and 3rd columns are both
address columns. The third column varies and may
be empty, start with a number or small/Capital letter.

All I want to do is eliminate the second , (comma) and replace it
with a space. Unfortunately I'm not strong in regular
expressions and everything I have tried so far isn't working.
There are over 30,000 records in this file. I would
much rather watch sed do it in 15 or so seconds than spend
15 or so days doing it by hand.

Can someone help me with this?

Thanks

John C.

"All my life I wanted to be someone;
I guess I should have been more specific."

________________________________________________________________
YOU'RE PAYING TOO MUCH FOR THE INTERNET!
Juno now offers FREE Internet Access!
Try it today - there's no risk!  For your FREE software, visit:
http://dl.www.juno.com/get/tagj.






Reply via email to