Issue
I am trying to replace whenever the actual text contains need to be replaced with text output in sed. It doesn't work to me.
Actual Text :
%d{ConversionPattern} %-5p [%c{1}] %m%n
Text output which i need
%d{ConversionPattern} %-5p [%c{1}] [%t] - %X{Sample} - %m%n
Command :
sed -i "/<param name=\"ConversionPattern\" value=\"%d{ConversionPattern} %-5p [%c{1}] %m%n\"\/>/s@@<param name=\"ConversionPattern\" value=\"%d{ConversionPattern} %-5p [%c{1}] [%t] - %X{Sample} - %m%n\"\/>@"
Solution
With your shown samples, please try following.
sed -E 's/(.*\])[[:space:]]++(.*)$/\1 [%t] - %X{Sample} - \2/' Input_file
Explanation: Using sed
's substitution capability and substituting everything from starting to till ]
and keeping it in 1st back reference, then keep everything after it into 2nd back reference. While substituting it mentioning - %X{Sample} -
between 2 of the back references values to insert new text.
NOTE: Above code will print the output on terminal, once you are happy with above results, then you could run above command with sed -i
option to perform an in-place save.
Answered By - RavinderSingh13 Answer Checked By - Dawn Plyler (WPSolving Volunteer)