sed - 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.
解决方案
问题是引导过程的 csv 文件中的字符串,在这里你松开了标点符号。将:替换为
testword[ -?],testword<indexterm><primary>testword</primary></indexterm>
:
testword\([ -?]\),testword\1<indexterm><primary>testword</primary></indexterm>
已经解决了你的问题。
推荐阅读
- flutter - 使用 Flutter 交换 GridItens 和计数移动
- html - 用 vh 固定的位置在 chrome 上无法正常工作,有什么帮助吗?
- javascript - 为什么更新前的mongo db响应值
- unity3d - 在没有 Bolt 的情况下使用统一
- css - Why can't I margin the div, why do I have to margin the child to margin the div?
- ios - saveInBackground (Parse) 抛出错误
- javascript - 用户在 context.switchToHttp().getRequest() nestjs 上未定义
- php - Laravel 8 中未正确添加自定义语言
- c - 将相同的内存与 2 种不同类型的变量一起使用,而不会在 C 中导致未定义的行为
- android - 应用程序 Flutter 中的 Firebase 缓存 .indexOn