Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex GNU Sed格式美国地址至街道、城市、州、邮编_Regex_Sed - Fatal编程技术网

Regex GNU Sed格式美国地址至街道、城市、州、邮编

Regex GNU Sed格式美国地址至街道、城市、州、邮编,regex,sed,Regex,Sed,我有一些客户的以下数据: 719 13th Street East, Glencoe MN, 55336 626 Valley Road, Montclair NJ, 07043 666 EAST DYER ROAD, SANTA ANA CA, 92705 20800 N. 135th Ave, Sun City West AZ, 85375 9775 Herring Gull Drive, Indianapolis IN, 46280 712 21st Street, Vero Beach

我有一些客户的以下数据:

719 13th Street East, Glencoe MN, 55336
626 Valley Road, Montclair NJ, 07043
666 EAST DYER ROAD, SANTA ANA CA, 92705
20800 N. 135th Ave, Sun City West AZ, 85375
9775 Herring Gull Drive, Indianapolis IN, 46280
712 21st Street, Vero Beach FL, 32960
PO BOX 324, PORT SALERNO FL, 34992
207 Middleton Road, Lafayette LA, 70503
5091 nw fiddle leaf ct, port saint lucie FL, 34986
347 Mayberry Lane, Dover DE, 19904
2648 SW 137th Ave, Miramar FL, 33027
4410 Williams Dr SUITE 104, Georgetown TX, 78628
17020 Windsor Court, Homer Glen IL, 60491
11 Technology Drive North, Warren NJ, 07059
655 Boylston St, Boston MA, 02116
1375 bishops terrace, wixom MI, 48393
4705 Center Blvd Apt. 808, Long Island City NY, 11109
5340 CORNELIA HWY, ALTO GA, 30510
1541 Paces Ferry North, Smyrna GA, 30080
603 west pacific coast hwy, wilmington CA, 90744
2503Paddock CT, Louisville KY, 40216
9421 Dunbar dr, Oakland CA, 94603
1804 Third Avenue Apt #8, New York NY, 10029
2504  bellaire  st, wantagh NY, 11793
1380 avon lane apt 21, north lauderdale  FL, 33068
如何使用SED regex将其格式化为 街道地址|城市|州|邮编

例如

谢谢

试试这个:

sed -e 's/\([A-Z]*\) \([A-Z][A-Z]\),/\1\|\2,/g' -e 's/, /\|/g'
它得到了所有,并取代了|。在此之前,搜索AAAA,并将其更改为AAAA,用于城市州部分

试验

试试这个:

sed -e 's/\([A-Z]*\) \([A-Z][A-Z]\),/\1\|\2,/g' -e 's/, /\|/g'
它得到了所有,并取代了|。在此之前,搜索AAAA,并将其更改为AAAA,用于城市州部分

试验

或:

输出:

719 13th Street East|Glencoe|MN|55336
626 Valley Road|Montclair|NJ|07043
666 EAST DYER ROAD|SANTA ANA|CA|92705
20800 N. 135th Ave|Sun City West|AZ|85375
9775 Herring Gull Drive|Indianapolis|IN|46280
712 21st Street|Vero Beach|FL|32960
PO BOX 324|PORT SALERNO|FL|34992
207 Middleton Road|Lafayette|LA|70503
5091 nw fiddle leaf ct|port saint lucie|FL|34986
347 Mayberry Lane|Dover|DE|19904
2648 SW 137th Ave|Miramar|FL|33027
4410 Williams Dr SUITE 104|Georgetown|TX|78628
17020 Windsor Court|Homer Glen|IL|60491
11 Technology Drive North|Warren|NJ|07059
655 Boylston St|Boston|MA|02116
1375 bishops terrace|wixom|MI|48393
4705 Center Blvd Apt. 808|Long Island City|NY|11109
5340 CORNELIA HWY|ALTO|GA|30510
1541 Paces Ferry North|Smyrna|GA|30080
603 west pacific coast hwy|wilmington|CA|90744
2503Paddock CT|Louisville|KY|40216
9421 Dunbar dr|Oakland|CA|94603
1804 Third Avenue Apt #8|New York|NY|10029
2504  bellaire  st|wantagh|NY|11793
1380 avon lane apt 21|north lauderdale |FL|33068
或:

输出:

719 13th Street East|Glencoe|MN|55336
626 Valley Road|Montclair|NJ|07043
666 EAST DYER ROAD|SANTA ANA|CA|92705
20800 N. 135th Ave|Sun City West|AZ|85375
9775 Herring Gull Drive|Indianapolis|IN|46280
712 21st Street|Vero Beach|FL|32960
PO BOX 324|PORT SALERNO|FL|34992
207 Middleton Road|Lafayette|LA|70503
5091 nw fiddle leaf ct|port saint lucie|FL|34986
347 Mayberry Lane|Dover|DE|19904
2648 SW 137th Ave|Miramar|FL|33027
4410 Williams Dr SUITE 104|Georgetown|TX|78628
17020 Windsor Court|Homer Glen|IL|60491
11 Technology Drive North|Warren|NJ|07059
655 Boylston St|Boston|MA|02116
1375 bishops terrace|wixom|MI|48393
4705 Center Blvd Apt. 808|Long Island City|NY|11109
5340 CORNELIA HWY|ALTO|GA|30510
1541 Paces Ferry North|Smyrna|GA|30080
603 west pacific coast hwy|wilmington|CA|90744
2503Paddock CT|Louisville|KY|40216
9421 Dunbar dr|Oakland|CA|94603
1804 Third Avenue Apt #8|New York|NY|10029
2504  bellaire  st|wantagh|NY|11793
1380 avon lane apt 21|north lauderdale |FL|33068

好办法也一样。您可以将[0-9][0-9][0-9][0-9][0-9]更改为[0-9]*。@fedorqui不想匹配邮政编码中除5位以外的其他数字。但是我改成了sed-r并且可以使用{5}。这也是个好方法,喜欢它。您可以将[0-9][0-9][0-9][0-9][0-9]更改为[0-9]*。@fedorqui不想匹配邮政编码中除5位以外的其他数字。但是我改成了sed-r并且可以使用{5}。你的答案也很好!我更喜欢这个+1!!你的回答也很好!我更喜欢这个+1!!州没有出现在单独的字段中可能是你怀疑太多:+只是为了澄清-我怀疑。。。它在MacBash上不起作用:状态不出现在单独的字段中可能是您怀疑太多:+只是为了澄清-我怀疑。。。它在MAC bash上不起作用:
sed -r 's/^(.*), *(.*) (..), ([0-9]{5})/\1|\2|\3|\4/'
719 13th Street East|Glencoe|MN|55336
626 Valley Road|Montclair|NJ|07043
666 EAST DYER ROAD|SANTA ANA|CA|92705
20800 N. 135th Ave|Sun City West|AZ|85375
9775 Herring Gull Drive|Indianapolis|IN|46280
712 21st Street|Vero Beach|FL|32960
PO BOX 324|PORT SALERNO|FL|34992
207 Middleton Road|Lafayette|LA|70503
5091 nw fiddle leaf ct|port saint lucie|FL|34986
347 Mayberry Lane|Dover|DE|19904
2648 SW 137th Ave|Miramar|FL|33027
4410 Williams Dr SUITE 104|Georgetown|TX|78628
17020 Windsor Court|Homer Glen|IL|60491
11 Technology Drive North|Warren|NJ|07059
655 Boylston St|Boston|MA|02116
1375 bishops terrace|wixom|MI|48393
4705 Center Blvd Apt. 808|Long Island City|NY|11109
5340 CORNELIA HWY|ALTO|GA|30510
1541 Paces Ferry North|Smyrna|GA|30080
603 west pacific coast hwy|wilmington|CA|90744
2503Paddock CT|Louisville|KY|40216
9421 Dunbar dr|Oakland|CA|94603
1804 Third Avenue Apt #8|New York|NY|10029
2504  bellaire  st|wantagh|NY|11793
1380 avon lane apt 21|north lauderdale |FL|33068
 sed -e 's/, /|/g' -e 's/ \([^ ]\+\)$/|\1/' file