Remove part of a column in a text file

I have a text file with delimiter "|" and sometimes the zipcode is in "5th" column or "6th" column. I want to scan the file and remove the "-2323" from the zipcode which has zip+4 digits

From

blah|blah|foo|bar||blah|945523-232|USA
 blah|blah|foo|bar||blah|foo|94555-2323|USA

To

blah|blah|foo|bar||blah|945523|USA
blah|blah|foo|bar||blah|foo|94555|USA

the samples you gave have ZIPs in the 7th and the 8-th columns (and 5th and 6th):

nawk -F'|' -v OFS='|' '{$7=substr($7,1, index($7,"-")-1)}1' myFile

Or with sed:

sed 's/-.*|/|/' file
>cat zips.txt | gawk  -F"|" '{FS=IFS=OFS="|"; $7=substr($7,1,5); $8=substr($8,1,5); print $0}'
blah|blah|foo|bar||blah|94552|USA
blah|blah|foo|bar||blah|foo|94555|USA

The "sed 's/-.*|/|/' file" works for me however how can I specify to remove the "-" on a particular column so that it doesnt touch ant other fields with "-" ? I n this case I only want to touch the field 12

blah|08-232|foo|bar|blah|aaa|aaa|asa|as|as|foo|94555-7777|blah

Assuming the zip code has a fixed length of 5 digits you can try this:

sed 's/\(.*[0-9][0-9][0-9][0-9][0-9]\)-[^|]*\(|.*\)/\1\2/' file
awk '{split($12,a,"-");$12=a[1]}1' FS="|" OFS="|" infile

Thanks all .