6
60
Fork
You've already forked dotfiles
6

optimize line for large inputs #6

Open
opened 2026年07月03日 16:05:49 +02:00 by data · 4 comments
sed -n "${lineno}p" -- "$@"
sed -n "${lineno}{p;q;}" -- "$@"

compare:

$ time seq 100000000 | sed -n '10p'
10
real 0m5.805s
user 0m5.157s
sys 0m2.521s
$ time seq 100000000 | sed -n '10{p;q;}'
10
real 0m0.017s
user 0m0.001s
sys 0m0.005s
https://codeberg.org/EvanHahn/dotfiles/src/commit/f7a9d94ae2254cb7e5f67e6e5bdb74b6467f6dec/home/bin/bin/line#L6 ``` sed -n "${lineno}{p;q;}" -- "$@" ``` compare: ``` $ time seq 100000000 | sed -n '10p' 10 real 0m5.805s user 0m5.157s sys 0m2.521s $ time seq 100000000 | sed -n '10{p;q;}' 10 real 0m0.017s user 0m0.001s sys 0m0.005s ```

This is useful. Could we remove that last semicolon in the command block, or is there a difference? So I'd do something like this?

-sed -n "${lineno}p" -- "$@"
+sed -n "${lineno}{p;q}" -- "$@"

It seems the same but I don't know much about sed.

This is useful. Could we remove that last semicolon in the command block, or is there a difference? So I'd do something like this? ```diff -sed -n "${lineno}p" -- "$@" +sed -n "${lineno}{p;q}" -- "$@" ``` It _seems_ the same but I don't know much about `sed`.
Author
Copy link

yes, that's the same

yes, that's the same

Would you mind making a pull request for this?

If not, I'll do it myself and credit you. But I won't be able to do that for a couple of weeks.

Would you mind making a pull request for this? If not, I'll do it myself and credit you. But I won't be able to do that for a couple of weeks.
Author
Copy link

No credits required, it was just a person is wrong on the internet moment :)

No credits required, it was just a person is wrong on the internet moment :)
Sign in to join this conversation.
No Branch/Tag specified
main
No results found.
Labels
Clear labels
No items
No labels
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
EvanHahn/dotfiles#6
Reference in a new issue
EvanHahn/dotfiles
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?