Sed or Grep to replace until end of line after pattern match

awkgrepsed

I need to replace all the characters after a pattern match until the end of the line while keeping the matched pattern

    blhablahPATTERN1XXXXXX

should read

    blhablahPATTERN1STUFFI_WANT_TO_INSERT

Everything I've tried so far has deleted the PATTERN1 as well…

Best Solution

Using sed

sed -r 's/(PATTERN1).*/\1STUFFI_WANT_TO_INSERT/' file

You need to capture PATTERN1 and use \1 in replacement string