Reputation: 739
I am trying to replace a character on a matched group only
Input:
Foo("test-me");
Looking for the following output:
Foo(TEST_ME);
The below command catch the text between quotes and set it uppercase
sed 's/Foo("\([^"]*\)");/Foo(\U\1);/'
=>
Foo(TEST-ME);
Just missing the
s/-/_/g
Upvotes: 1
Views: 778
Reputation: 89557
You need a conditional loop to replace any number of hyphens between the parenthesis:
sed 's/Foo("\([^"]*\)");/Foo(\U\1);/;:a;s/\(Foo([^)-]*\)-/\1_/;ta;'
details:
:a; # define the label "a"
s/\(Foo([^)-]*\)-/\1_/; # replace the first hyphen
ta; # if something is replaced, go to label "a"
Upvotes: 3