Leo Karti
Leo Karti

Reputation: 33

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?

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

Upvotes: 1

Views: 39

Answers (1)

Sundeep
Sundeep

Reputation: 23697

This should do (assuming GNU sed as \s is used):

sed 's/(declare-const\s\([a-z]*\)/(declare-fun \1()/'
  • By default, BRE is used, so ( and ) will be matched literally in search section. See also BRE-vs-ERE section in the manual
  • \( and \) will then become capture group
  • [a-z]* will match zero or more lowercase alphabets
  • rest of the line need not be matched and used in replacement section as it isn't modified


A few more observations:

  • ( and ) aren't special in replacement section
  • \s is again not special in replacement section, will insert s

Upvotes: 1

Related Questions