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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing format of postcode file

Status
Not open for further replies.

ianicr

IS-IT--Management
Nov 4, 2003
230
GB
I have a file with a list of uk postcodes eg.
DE13GJ
DE235LP
NE14HK
NE204ND

I need to seperate the file with a space in the correct place eg.
DE1 3GJ
DE23 5LP
NE1 4HK
NE20 4ND
I'm struggling with this because of the varying place for the space to go. Anyone got any ideas?
 
Try :

sed -e 's/^\(...\)/\1 /' input_file > output_file

Jean Pierre.
 
Sorry, I badly read your problem. My solution is not appropriate.

What is the logic for the space position ?

Jean Pierre.
 
Haven't time to figure it out, but we use this RE to validate a UK postcode

^[A-Z]{1,2}[0-9][0-9A-Z]{0,1}\s[0-9][A-Z]{2}|GIR 0AA$

Greg.
 
It is the way uk postcodes are formatted. XXX XXX or XXXX XXX.
It needs to be this way for printing postage labels. Thanks
 
This sed command add a space before the last 3 characters :

sed -e 's/\(...\)$/ \1/' input_file > output_file

Jean Pierre.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top