-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
  • 66,199
  • 35
  • 114
  • 250
yael
  • 12,598
  • 51
  • 169
  • 303

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,889
  • 2
  • 10
  • 22
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
  • 320,670
  • 36
  • 633
  • 936
  • 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