I'm looking for a sed
(or other Unix utility) command to find all instances of two string literals being concatenated, such that the command will replace these concatenations with the corresponding combination of the two string literals.
Specifically I am trying to automate these edits for Go and Java source code.
The command should not break if \"
occurs in either string literal, or if +
occurs in either string literal.
The command should handle any number of whitespace characters (or lack of whitespace characters) before and after the +
character.
Some examples:
"foo" + "bar"
=>"foobar"
"\"foo" + "bar"
=>"\"foobar"
"foo"+"bar"
=>"foobar"
"something else with " + "other words"
=>"something else with other words"
a + "bar" + "baz" + c
=>a + "barbaz" + c
"" + "bar" + "" + "foo"+ x
=>"barfoo"+ x
(I won't mind if the an answer uses a programming language instead of a Unix tool.)
c = '"'; s = "+"; c2 = '"'
as well? IOW, what language should we implement a tokeniser for?+
exist into fields". As for adding a minimal reproducible example, I think my question and the examples I give are sufficient. If you have more questions, I am happy to answer them.'c'
single quoted chars. It also has some/* comments */
where"
could occur unmatched. You could also have your plussed strings on different lines. Your sample could be addressed with something as simple assed 's/"[[:blank:]]*\+[[:blank:]]*"//g'