-1

we want to mark with "#" the matched line by sed or perl line liner

for example

we want to mark all lines in file that include the DatePattern word

log4j.appender.DRFA.DatePattern=.yyyy-MM-dd

expected output

#log4j.appender.DRFA.DatePattern

note - in case line already marked then it will not add another "#" before the line

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
yael
  • 13,106

2 Answers2

1

In case you don't want to remove the trailing date pattern (your spec is not quite clear), try

sed '/^[^#].*DatePattern/ s/^/#/' file
RudiC
  • 8,969
1

Prepending # to the line and also removing the = and whatever comes after it:

sed 's/^\([^#].*DatePattern\)=.*/#\1/' file

Alternatively, not removing the =:

sed 's/^[^#].*DatePattern/#&/' file
Kusalananda
  • 333,661
  • do you have another suggestion from my question on - https://unix.stackexchange.com/questions/460642/how-to-use-variable-with-awk – yael Aug 05 '18 at 14:21