Looking at your
address-list.csv file, this appears to be a case of Garbage In, Garbage Out.
I doubt if you can do what you want with
sed. In fact, I doubt if there's any tool or scripting language that you can use.
You may be able to do something vaguely useful with
perl or similarly capable language but there doesn't even seem to be a consistent format to the addresses - most have what looks like a six-digit postal code, but not all lines do. Many seem to have the city name and the country as the 2nd-last and last fields (e.g. "Kolkata INDIA") but some skip the country, some have the city name before the postal code, some have a town name followed by the street address, and some have neither city nor country. Some have the personal/family/business name before the street address, some have it after, some don't have a name.
In short, the entire file is a mess that can't be processed automatically without a huge set of street names, city/town/suburb names, postal codes, state names, etc....and even if you had such a list, trying to match all of those against substrings of each line would be horrendously complex.
Processing this requires intelligence (human or artificial), not a regular expression or other formula.
This is the problem with trying to process free-form text that doesn't even pretend to have any structure. With some of the oddities in the file, I'd say that this .csv file goes way beyond merely free-form and into "bizarre-form".
And this is why you never let users enter addresses in free-form text fields. You give them a standard set of fields for the various parts that make up an address - name, street number, street name, suburb, city, post code, country, etc. Some users will still manage to screw it up somehow but the vast majority of your data will be in a usable form...and the remainder can either be fixed by hand or just discarded.
IMO, your best option is to manually edit it with a text editor into some standardised form that can be easily processed with line-oriented tools like
vi is particularly good at such repetitive editing tasks - modal editors excel at such tasks, and a skilled person can finish in a tiny fraction of the time that it would take using a simple, modeless editor like
I would suggest something like:
name:street address:postal code:city:country:comments
NOTE: there aren't many
: characters in the .csv file and those that are there can be removed or replaced with
. characters. Also,
country may be optional (it seems to be a list of entirely Indian addresses) but it doesn't hurt to have it - your code could default to "India" if the country field is empty.
Alternatively, maybe you can try to find an address list that isn't garbage...but i guess you're trying to create one because this is all you have.