Hi Christian:
Thank you for your help and support. I appreciate you having me jump
through these hoops! I do have more code that is in my LoB that I wish
to share, but it is more complex than this one - and I'm not ready yet
(and have little time to massage it into shape right now).
Attached is, hopefully, the final version.
Best Regards,
Steve
On 4/14/26 2:58 AM, Christian Moe wrote:
Steve Holtz<[email protected]> writes:
I forgot to commit before creating the patch.... And, grief, I didn't
look at the patch before sending it. This is my first time sending
patched in this manner!
Happens, no problem. The patch system takes some getting used to, but
has the advantage of keeping everything in the mailing list.
Please let me know if this looks better, or if you have suggestions!
We're almost there. Three last things -- I could just fix them, but
maybe you'd like to take a last pass?
1. The example in your last patch doesn't test right because:
- There's still a hyphen in 'line-str' in the CALL line; it should be an
underscore.
- Python's ~range(10)~ actually yields 0-9, not 1-10, so the results
shown are off by one from what the actual output would be. Either
source or results need adjusting.
2. All the other LoB blocks are named with hyphens (kebab case) rather
than underscore, so let's stick to that convention: the block NAME
should be changed to 'extract-lines' and the CALL line changed
accordingly.
3. Note the commit message conventions (we follow them for Worg as well
to the extent it makes sense):
https://orgmode.org/worg/org-contribute.html#commit-messages
So your commit message should start with a line with the file changed
and a short description of the overall change, e.g., minimally,
library-of-babel.org: Add extract-lines
It could optionally go on after a blank line with a more detailed
changelog entry. I don't think that's needed here, but if you do, see
the above link for formatting.
Regards,
Christian
--
Steven J Holtz
Instructor
Department of Computer Science
University of Minnesota Duluth
https://www.d.umn.edu/~sholtz/
From d5ff3d22efc40859cb76ada4ce8754ee29771705 Mon Sep 17 00:00:00 2001
From: Steven J Holtz <[email protected]>
Date: Tue, 14 Apr 2026 09:13:21 -0500
Subject: [PATCH] library-of-babel.org: Add extract-lines
---
library-of-babel.org | 46 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
diff --git a/library-of-babel.org b/library-of-babel.org
index 0e35313c..7d63e723 100644
--- a/library-of-babel.org
+++ b/library-of-babel.org
@@ -411,6 +411,52 @@ span. Note the use of LaTeX, rather than Org-mode, markup.
| t | t | t |
| t | t | t |
+* Extract lines from output with sed
+
+To extract only certain lines from the output of a source code block.
+
+#+name: extract-lines
+#+header: :var data="" line_str=""
+#+header: :results output
+#+begin_src sh
+ echo "${data}" | sed -n "${line_str}"
+#+end_src
+
+To use this, name the source code block that will be generating the
+lines to extract from. Usually, this source code block will not export
+anything. So, it will look like this:
+
+#+begin_example
+,#+name: source
+,#+header: :results output :exports none
+,#+begin_src python
+ for i in range(10):
+ print(i)
+,#+end_src
+#+end_example
+
+The =data= variable in =extract-lines= must be set to the output from
+this source code block.
+
+And the =line_str= variable must be passed the desired lines to
+extract using the =sed= syntax for [[https://www.gnu.org/software/sed/manual/sed.html#Range-Addresses][selecting by address
+ranges]]. Multiple ranges can be selected by separating them by
+semicolons.
+
+Then call the =extract-lines= block. To extract lines 1–2, 5, and 7–9
+from the output generated by the =source= source code block above:
+
+: #+call: extract-lines(data=source(), line_str="1,2p;5p;7,9p") :results output :exports results
+
+#+begin_example
+0
+1
+4
+6
+7
+8
+#+end_example
+
* Misc
** File-specific Version Control logging
--
2.43.0