From Newsgroup: gnu.emacs.help
Cecil Westerhof <
Cecil@decebal.nl> writes:
Ben <ben.usenet@bsb.me.uk> writes:
Cecil Westerhof <Cecil@decebal.nl> writes:
I have a log file in which most lines are not interesting most of the
time. These line all contain a certain string. Is there a way to
display only those lines that do not contain a certain string?
That would also be an option, but at the moment I chose the following function:
(defun dcbl-reduced-logfile (filter-string)
(interactive "s Filter String: ")
(message filter-string)
(let ((buffer-name (generate-new-buffer-name "reduced-logfile"))
(text (buffer-substring (point-min) (point-max))))
(switch-to-buffer buffer-name)
(insert text)
(beginning-of-buffer)
(delete-matching-lines filter-string)
))
Just whipped it up, so I am open for improvements.
(Should probably put name of current buffer in the new buffer name.)
A little bit better version:
(defun dcbl-reduced-logfile (filter-string)
(interactive "sFilter String: ")
(message filter-string)
(let ((buffer-name (generate-new-buffer-name
(concat "reduced-logfile"
"#"
filter-string
"#"
(file-name-sans-extension (buffer-name)))))
(text (buffer-substring (point-min) (point-max))))
(switch-to-buffer buffer-name)
(insert text)
(beginning-of-buffer)
(delete-matching-lines filter-string)
))
My log files are often like 2022-05-18.log, so it is handy to have the
filter string included.
--
Cecil Westerhof
Senior Software Engineer
LinkedIn:
http://www.linkedin.com/in/cecilwesterhof
--- Synchronet 3.21d-Linux NewsLink 1.2