Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
An idea for fast "last-N-lines" read
- X-seq: zsh-workers 40876
- From: Sebastian Gniazdowski <psprint3@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: An idea for fast "last-N-lines" read
- Date: Mon, 20 Mar 2017 23:04:42 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:message-id :mime-version:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=KxTe8jYY8gy6wXb24C2+PHyNFs24JhXyT4BVe9iydqs=; b=t0e5oG1x hAeDzGUFde3d9QM8m3eOmZ7SR0bN/wB63HU8KyXxJp+xgpvJycXplNmoixMzkaFq pU4aRSzALjqUrXDoJIWbrL+TOaL6tuDO47YzGTIJgR8x6tTCYYVzD5CzkInPIBHm O20wGBPVAWCVVuvX5y5oswM1FaawPAGIDZxubgMVAmOmUjkB2Cs3yN+89V8jzGCU wXFJdGaHy6J2SnnKr/JRPOkvdfO/ULdRtM0SNkya3/9pE9v0FRIQ7J8HKq1i3ae3 i7QvkhCCkBERxMZeJjyrDPe0fnmnbLQ1/Flr9KB027HtWjJ7N9Ufqx3IOGNs6y6n uy4LJ1U4USDxWQ==
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:message-id:mime-version:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm1; bh=KxTe8jYY8gy6wXb24C2+PHyNFs24J hXyT4BVe9iydqs=; b=Zu741SclH/OiH4Ev2MMN2BUd1AUiGrN3M8g+/KXl15tMs ooIRZeeUJnR0uQLXCv8wptEy63/YqDPiJ6TyVvGymQELpX8mnsCROGkb6bgRpjS6 qmN0bZVceALdFi3zBqh7Medr+gEOyzor7CUWyO7wgjnjG/MCEeGeUzbaCIlPYJCA 5pPEQYmKJMi73O0WrqvlbG4rgw6Hy0HztQjoyYleFmemW/vRl247psRNbMRYTkx4 5W1cVz84ga/ujtUeStZPSa88Rtw9CVgBhTjNwY4/CF14F5htpOsgH4mU1zB8V796 CEq5dmvVXMHz1clr4siWRta/NaQz6tcj7Jx1qJsZw==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
Hello
I read somewhere that to read "last-N-lines" it is good to memory-map
the file. Cannot check with Zsh:
for (( i=size; i>=1; --i)); do
if [[ ${${mapfile[input.db]}[i]} = $'\n' ]]; then
echo Got newline / $SECONDS
...
This gives:
Got newline / 0.1383100000
Got newline / 16.0876810000
Got newline / 26.8089250000
for 2 MB file – apparently because it memory-maps the file on each
newline check.
So the idea is to add such feature. It would allow to run Zsh on
machines where e.g. periodic random check of last 1000 lines of
gigabyte-logs would be needed. It's possible that even Perl doesn't have
this. I'm thinking about: $(<10<filepath) syntax, that would return
buffer with 10 last lines, to be splited with (@f). Or maybe
$(<10L<filepath) for lines, and $(<10<filepath) for bytes. Maybe it's
easy to add? Otherwise, extension to zsh/mapfile could be added, or a
new module written.
BTW, (@f) skips trailing \n\n... That's quite problematic and there's
probably no workaround?
--
Sebastian Gniazdowski
psprint3@xxxxxxxxxxxx
Messages sorted by:
Reverse Date,
Date,
Thread,
Author