首页 > 解决方案 > sed replace from csv include last character of search term

问题描述

I am trying to replace a list of words found in a csv file with index markup (docbook). The csv is in this format:

testword[ -?],testword<indexterm><primary>testword</primary></indexterm>

This finds all occurrences of the testword with punctuation at the end. This part works. However, I need the final punctuation mark to be included in the replace part of the sed command.

sed -e 's/\(.*\)/s,\1,g/' index.csv > index.sed

sed -i -f index.sed file.xml

So e.g. This is a testword, in a test. Would get replaced with This is a testword,<indexterm><primary>testword</primary></indexterm> in a test.

标签: seddocbook

解决方案


问题是引导过程的 csv 文件中的字符串,在这里你松开了标点符号。将:替换为 testword[ -?],testword<indexterm><primary>testword</primary></indexterm> testword\([ -?]\),testword\1<indexterm><primary>testword</primary></indexterm>

已经解决了你的问题。


推荐阅读