将引号替换为“``”和“”“”
我有一个包含许多 "
标记的文档,但我想将其转换为在 TeX 中使用。TeX
使用 2 个 ` 标记作为开始引号,使用 2 个 ' 标记作为结束引号。
我只当 "
以偶数出现在单行上(例如,该行有 2、4 或 6 个 "
)时,想要对这些进行更改。例如
"This line has 2 quotation marks."
--> ``This line has 2 quotation marks.''
"This line," said the spider, "Has 4 quotation marks."
--> ``This line,'' said the spider, ``Has 4 quotation marks.''
"This line," said the spider, must have a problem, because there are 3 quotation marks."
--> (unchanged)
我的句子永远不会跨行,所以没有需要检查多行引号
这些引号。
,因此我可以手动更改
I have a document containing many "
marks, but I want to convert it for use in TeX.
TeX uses 2 ` marks for the beginning quote mark, and 2 ' mark for the closing quote mark.
I only want to make changes to these when "
appears on a single line in an even number (e.g. there are 2, 4, or 6 "
's on the line). For e.g.
"This line has 2 quotation marks."
--> ``This line has 2 quotation marks.''
"This line," said the spider, "Has 4 quotation marks."
--> ``This line,'' said the spider, ``Has 4 quotation marks.''
"This line," said the spider, must have a problem, because there are 3 quotation marks."
--> (unchanged)
My sentences never break across lines, so there is no need to check on multiple lines.
There are few quotes with single quotes, so I can manually change those.
How can I convert these?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是我的一句台词,对我有用:
并且该台词有长版本的注释:
您可以通过以下方式运行此脚本:
This is my one-liner which is works for me:
And there is long version of this one-liner with comments:
You may run this script by:
这是我使用重复
sed
的一行代码:(注意:如果文件中已经存在反引号 (`),则它将无法正常工作,但否则应该可以解决问题)
编辑:
通过简化删除了反勾号错误,现在适用于所有情况:
带有注释:
Here's my one-liner using repeated
sed
's:(note: it won't work correctly if there are already back-ticks (`) in the file but otherwise should do the trick)
EDIT:
Removed back-tick bug by simplifying, now works for all cases:
With comments:
使用
awk
说明
使用
sed
Using
awk
Explanation
Using
sed
这可能对您有用:
说明:
h
"
的s/"\([^"]*\ )"/``\1''\'\''/g
"
,如果找到则恢复到原始行/"/g
This might work for you:
Explanation:
h
"
'ss/"\([^"]*\)"/``\1''\'\''/g
"
and if found revert to original line/"/g