我正在尝试创建file.xml,我有一个包含1000个城市的city.txt文件,每行一个城市名称。
file.xml应该具有city.txt
中每个城市的格式(代码块) <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>
最好的方法是什么?
由于
答案 0 :(得分:1)
您可以编写awk
脚本:
#!/usr/bin/awk -f
BEGIN{
print "<ss:Row ss:Height='22'>"
}
{
print "<ss:Cell>"
print "<ss:Data ss:Type='String'>" $0 "</ss:Data>"
print "</ss:Cell>"
}
END{
print "</ss:Row>"
}
要运行此脚本:
$ awk -f xml.awk city.txt