<p>我有一个文本文件,包含数千个条目,例如:</p>
<pre><code>@INBOOK{Abu-Lughod1991,
chapter = {Writing against culture},
pages = {137-162},
title = {Recapturing anthropology},
publisher = {School of American Research Press},
year = {1991},
editor = {Richard Fox},
author = {Abu-Lughod, Lila},
address = {Santa Fe /NM},
abstract = {Im Zusammenhang mit der Debatte um die writing culture fomuliert AL
eine feministische Kritik und zeigt, wie von dort doch Anregungen
für die Reflektion der Schreibweise und Repräsentation gekommen sind.*},
crossref = {Rabinow1986},
keywords = {Frauen; Feminismus; Erzählung als EG; Repräsentation; Roman; Schreibtechnik;
James Clifford; writing culture; Dialog;},
owner = {xko},
systematik1 = {Anth\theor\Ethnographie},
systematik2 = {Anth\theor\Text & Ges},
timestamp = {1995-12-02}
}
</code></pre>
<p>我将把关键字字段中的分号替换为逗号。但仅在“关键字”字段中-其他字段应保持不变:</p>
^{pr2}$
<p>我不是一个程序员,也许下面的代码片段是一个很好的起点,如果有人能完成我将非常感激。在</p>
<pre><code>outfile = open("literatur_comma.txt", "w")
for line in open("literatur_semicolon.txt", "r"):
if line # starts with "keywords" replace all semicolon with comma
outfile.write(line) # write in new file
outfile.close()
</code></pre>
<p>非常感谢!在</p>
<p>编辑:
谢谢你的答案和代码,太好了!
我在思想上犯了一个错误,如果我使用代码包装器(带outfile),那么它会创建一个包含关键字的新文件。
如何使用同一个文件,并且只将分号替换为关键字行中的逗号?在</p>