简体   繁体   English

sed 替换字符串

[英]sed replacement for a string

(declare-const buabor Real)

which I want to replace as我想替换为

(declare-fun buabor () Real)

can it be done with sed?可以用 sed 完成吗?

I tried我试过了

sed 's/(declare-const\s([a-z])\s(Real))/(declare-fun\s\2\(\)\3/)g'

but was not able to get the result any help would be great但无法得到结果任何帮助都会很棒

This should do (assuming GNU sed as \s is used):这应该可以(假设GNU sed作为\s ):

sed 's/(declare-const\s\([a-z]*\)/(declare-fun \1()/'
  • By default, BRE is used, so ( and ) will be matched literally in search section.默认情况下,使用 BRE,因此()将在搜索部分按字面意思匹配。 See also BRE-vs-ERE section in the manual另请参阅手册中的BRE-vs-ERE部分
  • \( and \) will then become capture group \(\)然后将成为捕获组
  • [az]* will match zero or more lowercase alphabets [az]*将匹配零个或多个小写字母
  • rest of the line need not be matched and used in replacement section as it isn't modified该线路的rest未经过修改,无需匹配并用于替换部分


A few more observations:还有一些观察:

  • ( and ) aren't special in replacement section ()在替换部分并不特殊
  • \s is again not special in replacement section, will insert s \s在替换部分再次不是特殊的,将插入s

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM