我有一个包含 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