Search/Replace capabilities of KATE 22.12.3

Rens Oliemans hallo at rensoliemans.nl
Fri Feb 7 12:59:06 GMT 2025


Richard Owlett <rowlett at access.net> writes:

> Raises the question:
>     "In a KATE macro, instead of doing a "Replace:" operation could
>      there be an "append to a different file" operation be performed"?

I'm not sure; I'm not that knowledgeable with KATE. Perhaps someone else can
chime in.

Personally, I would do that with 'grep', combined with 'sed' or 'awk' if it's a
complex query. It is of course better to not have to learn these tools if KATE
can do it. If it cannot do natively, a KATE-only "hack" could be to copy the
file to a temporary file and replace the contents you _don't_ want to see with
nothing. Depending on how your regex looks, this might be more effort to get
working, or not.

Alternatively, learning the very basics of 'grep' could be worth it and should
get you a long way, possibly just in order to create files which you can later
edit more easily with KATE. A very quick example:

  Extracting all the chapter headings of a book to a file. In my file, it has
  the format:
 
    <h2><a id="chapter-x"></a>
    CHAPTER NAME</h2>

  And the following grep command will extract all this:

    grep --extended-regexp '([A-Z ]+)</h2>' pg1727-images.html >> headings.txt

  And will result in the following contents of headings.txt:

    <<whatever was already in headings.txt>>
    PREFACE TO FIRST EDITION</h2>
    PREFACE TO SECOND EDITION</h2>
    THE ODYSSEY</h2>
    BOOK I</h2>
    BOOK II</h2>
    BOOK III</h2>
    ...

> Do you realize your posts do not appear in the archives at
>    https://mail.kde.org/pipermail/kde/2025-February/thread.html
> ????

I am a non-member, so my posts are being held for some time. I'm not sure how to
rectify this, I subscribed to the mailing list but I might have missed a step.

> Thanks again for your guidance.

Glad to help!


More information about the kde mailing list