在 Shell 中将多个字符串解析为单个变量

Parse multiple string as single variable in Shell

假设我有包含以下字符串的文件。

Paris, France baguette
Madrid, Spain callos
Sheffield, England steak

我想遍历文件,打印 City 和 culinary。

City: Paris, France
Food: baguette

棘手的部分是国家和城市之间有一个 space,显然简单的 while read -r 不起作用,因为白色 space.

您需要在国家和食物之间使用其他分隔符 例如“,”

find . -type f -name "*.txt"|xargs -I {} sh -c "awk -F, '{print \"City: \" $1 \",\" $2; nexline; print \"Food: \"$3}' {}"

City: London, Great Britain
Food: fish & chips
City: Paris, France
Food: baguette
City: Madrid, Spain
Food: callos
City: Sheffield, England
Food: steak