我有一些不同国际格式的addresses.csv
Example Street 1
Teststraße 2
Teststr. 1-5
Baker Street 221b
221B Baker Street
19th Ave 3B
3B 2nd Ave
1-3 2nd Mount x Ave
105 Lock St # 219
Test Street, 1
BookAve, 54, Extra Text 123#
例如我们在德国写作Teststraße 2
,在美国2 Test Street
有没有办法分离/提取所有街道名称和街道号码? 输出名称.csv
Example Street
Teststraße
Teststr.
Baker Street
Baker Street
19th Ave
2nd Ave
2nd Mount Good Ave
Lock St # 219
Test Street
BookAve
输出数字.csv
1
2
1-5
221b
221B
3B
3B
1-3
105
1
54
输出-extra_text.csv
Extra Text 123#
我正在使用 macOS 13.. shell 是 zsh 5.8.1 或 bash-3.2
我的想法是:您可以像这样先对地址进行排序:
x=The-adress-line;
if [ x = "begins with a letter"];
then
if [ x = "begins with a letter + number + SPACE"];
then
echo 'something like "1A Street"';
# NUMBER = '1A' / NAME = 'Street'
else
echo 'It begins with the STREET-NAME';
fi;
elif [ x = "begins with a number"];
then
echo 'maybe STREET-NAME like "19th Ave 19B" or STREET-NUMBER like "19B Street"';
# NUMBER = '19B' / NAME = '19th Ave' or 'Street'
if [ x = "begins with a number + SPACE"];
then
echo 'It begins with the STREET-NUMBER like "1 Street"';
# NUMBER = '1' / NAME = 'Street'
elif [ x = "is (number)(text)(space)(text)(number(maybe-text))"];
then
echo 'For example 19th Street 19B -> The last number+text is the number (19B)'
# NUMBER = '19B' / NAME = '19th Street'
elif [ x = "is (number(maybe-text))(space)(number)(text)(space)(text)"];
then
echo 'For example 19B 19th Street -> The first number+text is the number (19B)'
# NUMBER = '19B' / NAME = '19th Street'
else
echo 'INVALID';
else
echo 'INVALID';
fi;