unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Nick Dokos <ndokos@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: Regex to match lines with a specific number of words
Date: Tue, 26 Apr 2022 19:55:51 -0400	[thread overview]
Message-ID: <87tuafl7qw.fsf@alphaville.usersys.redhat.com> (raw)
In-Reply-To: 87czh7ttzt.fsf@fastmail.fm

Joost Kremers <joostkremers@fastmail.fm> writes:


> I've been trying to come up with a regex that will match any line containing at
> least 30 words in order to kill them from the buffer (preferably with
> `kill-matching-lines`, because I need to move the lines to another buffer.)
>
> ...
>
> Passing this to `flush-lines` simply deletes everything in the buffer starting
> at point, telling me it "[d]eleted 1 matching line", even though (many) more
> lines were deleted. Adding ^ and $ around the regex didn't have any effect.
>

Do you have to do it in emacs? Why not use `awk'? It could be as simple as

awk 'NF < 30  {print;}'

and saving the other lines to a different file is not much more difficult:

awk 'NF < 5 {print;}
NF >= 5 { print > "long-stuff.txt"}'

-- 
Nick

"There are only two hard problems in computer science: cache invalidation, naming things, and off-by-one errors." -Martin Fowler




  parent reply	other threads:[~2022-04-26 23:55 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-23 19:44 Regex to match lines with a specific number of words Joost Kremers
2022-04-23 20:58 ` Thibaut Verron
2022-04-23 21:20   ` Joost Kremers
2022-04-23 21:46     ` Thibaut Verron
2022-04-23 22:11       ` [External] : " Drew Adams
2022-04-23 22:32         ` Thibaut Verron
2022-04-23 22:21       ` Joost Kremers
2022-04-23 22:46   ` Stefan Monnier via Users list for the GNU Emacs text editor
2022-04-24 14:31     ` Joost Kremers
2022-04-26 23:55 ` Nick Dokos [this message]
2022-04-27  7:23   ` Jean Louis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tuafl7qw.fsf@alphaville.usersys.redhat.com \
    --to=ndokos@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).