Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64503

Re: Separate Address number and name

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: Separate Address number and name
Date 2014-01-22 15:40 +0000
Organization A noiseless patient Spider
Message-ID <lboopb$668$2@dont-email.me> (permalink)
References <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com>

Show all headers | View raw


On Tue, 21 Jan 2014 15:49:16 -0800, Shane Konings wrote:

> I have the following sample from a data set and I am looking to split
> the address number and name into separate headings as seen below.
> 
> FarmID	Address 1	1067 Niagara Stone 2	4260 Mountainview 
3	25 Hunter 4
> 1091 Hutchinson 5	5172 Green Lane 6	500 Glenridge 7	471 Foss 
8	758
> Niagara Stone 9	3836 Main 10	1025 York
> 
> 
> FarmID	AddressNum    AddressName 1	1067          Niagara 
Stone 2	4260   
>       Mountainview 3	25            Hunter 4	1091          Hutchinson 5
> 5172          Green Lane 6	500           Glenridge 7	
471           Foss
> 8	758           Niagara Stone 9	3836          Main 10	
1025          York
> 
> I have struggled with this for a while and know there must be a simple
> method to achieve this result.

Unfortunately the vagaries of nntp, my client and the google nntp posting 
host are such that I can't discern the format of your data from your post.

However, if as I think you have a text field that is always:

<1 or more digits><1 or more spaces><the rest>

where you want to capture the initial "1 or more digits" and "the rest" 
as 2 data elements then this should be possible with a simple re:

(\d+)\s+(.*)

If you have numeric id, whitespace, numeric addr bit, whitespace, the 
rest, then you may need something more like:

(\d+)\s+(\d+)\s+(.*)

The assumption is that it's not necessary to hold your hand through the 
whole looping through the input and applying the re to each line, then 
reading the captured bits and using them process.

-- 
Denis McMahon, denismfmcmahon@gmail.com

Back to comp.lang.python | Previous | NextPrevious in thread | Find similar | Unroll thread


Thread

Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 15:49 -0800
  Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 00:55 +0100
    Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:01 -0800
  Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:06 -0800
    Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 02:04 +0100
    Re: Separate Address number and name Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-22 10:08 +0000
    Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 17:35 +0000
      Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-23 18:11 +0000
  Re: Separate Address number and name Asaf Las <roegltd@gmail.com> - 2014-01-21 16:08 -0800
  Re: Separate Address number and name Ben Finney <ben+python@benfinney.id.au> - 2014-01-22 11:08 +1100
  Re: Separate Address number and name John Gordon <gordon@panix.com> - 2014-01-22 02:46 +0000
    Re: Separate Address number and name Tim Chase <python.list@tim.thechases.com> - 2014-01-21 21:03 -0600
  Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 15:40 +0000

csiph-web