我有一個包含超過 1000 行的 city.txt 檔案(每行一個城市名稱),還有一個包含以下程式碼區塊的 format.xml 檔案:
<ss:Row ss:Height ="22">
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">CITY-FROM-TEXT-FILE-LINE-1</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">CALIFORNIA</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">CA</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
<ss:Cell>
<ss:Data ss:Type="String">xx</ss:Data>
</ss:Cell>
</ss:Row>
我需要一個 bash 腳本來複製 format.xml 並將 CITY-FROM-TEXT-FILE-LINE-1 更改為清單中的城市名稱。每個城市一個代碼塊。
你能幫我嗎 ?
答案1
$ cat city.txt | \
while read CITY; do \
sed "s/CITY-FROM-TEXT-FILE-LINE-1/$CITY/" format.xml; \
done