如何从终端使用正则表达式替换

时间:2019-03-27 15:02:31

标签: linux bash awk sed terminal

我想使用以下默认的debian linux工具之一在index.html中进行替换:

="([A-z]+).html"

使用

="javadoc/$1.html"

index.html文件包含以下内容:

<frame src="overview-frame.html" name="packageListFrame" title="All Packages">
<frame src="allclasses-frame.html" name="packageFrame" title="All classes and interfaces (except non-static nested types)">
</frameset>
<frame src="overview-summary.html" name="classFrame" title="Package, class and interface descriptions" scrolling="yes">
Link to <a href="overview-summary.html">Non-frame version</a>.</p>

我已经开始使用sed,但是出现表达错误:

sed -E 's,="([^"]+)\.html",="javadoc\/\1.html",' public/javadoc/index.html

2 个答案:

答案 0 :(得分:1)

尝试一下:

const currentObject = {myObject : [{'attribute1':'foo1','attribute2':'bar1','attribute3':'test1'},{'attribute1':'foo2','attribute2':'bar2','attribute3':'test2'},{'attribute1':'foo3','attribute2':'bar3','attribute3':'test3'},]}
const updateObject = {myObject : {'test1':'newtest1','test2':'newtest2','test3':'newtest3'}}

currentObject.myObject.forEach(e => {

Object.entries(e).forEach(([key,value]) => {
    if(updateObject.myObject[value]){
      e[key] = updateObject.myObject[value]
    }
  })
})

console.log(currentObject)

解释

sed "s/\([^\"]*\.html\)/javadoc\/\1/g" public/javadoc/index.html

答案 1 :(得分:1)

我不完全理解你的意思

sed -E 's,="([^"]+)\.html",="javadoc/\1.html",' public/javadoc/index.html