-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

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
1

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

sed '/^[^#].*DatePattern/ s/^/#/' file

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.