我有以下数据,尽我所能,但没有做到......
Las Vegas Nevada 89102|US|Katrina Roetteler
zhen fo shan guang dong 528318|CN|tu min jung
Zurich CH8022|CH|Kevin M Pearl
Cheltenham GL52 8XX|UK|Kevin M Pearl
Melbourne Vic 3000|AU|brent chandler
Bratislava 821 03|Slovak Republic|SUSTRIK MARTIN MGR.
Zurich 8032|CH|David Graf
Tokyo 178-0063|JP|takahiro ichihashi
我需要改变它:
Las Vegas Nevada|89102|US|Katrina Roetteler
zhen fo shan guang dong|528318|CN|tu min jung
Zurich |CH8022|CH|Kevin M Pearl
Cheltenham|GL52 8XX|UK|Kevin M Pearl
Melbourne Vic|3000|AU|brent chandler
Bratislava |821 03|Slovak Republic|SUSTRIK MARTIN MGR.
Zurich|8032|CH|David Graf
Tokyo|178-0063|JP|takahiro ichihashi
基本上将Zipcode / Postcode放在另一列(全球各地客户的不同类型的邮政编码)中,Zipcode / Postcode在第一个竖线之前。
谢谢!
答案 0 :(得分:2)
使用sed:
sed 's/^\([A-Za-z ]*\) \([-A-Z 0-9]*|\)/\1|\2/' input
<强>输出强>
Las Vegas Nevada|89102|US|Katrina Roetteler
zhen fo shan guang dong|528318|CN|tu min jung
Zurich |CH8022|CH|Kevin M Pearl
Cheltenham|GL52 8XX|UK|Kevin M Pearl
Melbourne Vic|3000|AU|brent chandler
Bratislava |821 03|Slovak Republic|SUSTRIK MARTIN MGR.
Zurich|8032|CH|David Graf
Tokyo|178-0063|JP|takahiro ichihashi
答案 1 :(得分:1)
以下正则表达式:
sed 's/ \([A-Z]*[0-9][0-9]*\)/\|\1/'
答案 2 :(得分:1)
让你开始使用awk的东西:
{
for (i = 1; i < NF; i++) {
if ($i~/\|/) {
if ($(i-1)~/[0-9]/) {
$(i-1) = "|"$(i-1)
} else {
$i = "|"$i
}
break
}
}
}
{print}
输出:
Las Vegas Nevada |89102|US|Katrina Roetteler
zhen fo shan guang dong |528318|CN|tu min jung
Zurich |CH8022|CH|Kevin M Pearl
Cheltenham |GL52 8XX|UK|Kevin M Pearl
Melbourne Vic |3000|AU|brent chandler
Bratislava |821 03|Slovak Republic|SUSTRIK MARTIN MGR.
Zurich |8032|CH|David Graf
Tokyo |178-0063|JP|takahiro ichihashi