假設我有包含以下字串的檔案。
Paris, France baguette
Madrid, Spain callos
Sheffield, England steak
我想遍歷檔案,列印城市和烹飪。
City: Paris, France
Food: baguette
棘手的部分是 Country 和它的 City 之間有一個空格,while read -r由于空格,顯然簡單不起作用。
uj5u.com熱心網友回復:
您需要國家和食物之間的其他分隔符,例如“,”
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
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/451681.html
上一篇:查找包含2個字符的檔案名,然后查找其中包含數字的檔案名
下一篇:什么是參考命令?
