help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Regex to match lines with a specific number of words


From: Nick Dokos
Subject: Re: Regex to match lines with a specific number of words
Date: Tue, 26 Apr 2022 19:55:51 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]