Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Split Line on Uppercase Letter in string

Status
Not open for further replies.

Trancemission

Technical User
Oct 16, 2001
108
GB
Okay I have numerous files which I have exported from my bosses crap contact management system.

The problem is the data is exported all on one line, and where there should be a line break there is nothing, an example:

Some Company;123 My RoadMy StreetCounty

As you can see I can get the company name but the address,street and county are stuck together. What I need is to split the line if a Uppercase Character is next to a lower case charactor.

Any ideas?!?

Cheers
 

Code:
BEGIN { FS=";" }
{ print $1
  rest = $2
  while ( match( rest, /[a-z][A-Z]/ ) )
  { print substr( rest, 1, RSTART )
    rest = substr( rest, RSTART+1 )
  }
  if (rest) print rest
  print ""
}
 
You may try this sed script to create field separators:
sed 's!\([a-z]\)\([A-Z]\)!\1;\2!g' /path/to/input >output.csv

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 

If you want ";" between each field:

Code:
{ while ( match( $0, /[a-z][A-Z]/ ) )
    $0=substr($0,1,RSTART) ";" substr($0,RSTART+1)
  print
}
 
Thanks for your replies,

I am liking the sed example - not really had much experiance with it, will read up. I assume I can turn all the lines in a file [each contact has it's own file] to one line {remove spaces, Chr returns etc] and then merge them files :)

Thanks again

Trancemission
=============
If it's logical, it'll work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top