Hi Christian:

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!

Here it is.

Please let me know if this looks better, or if you have suggestions!

Best,
Steve

On 4/13/26 4:09 PM, Christian Moe wrote:
Steve Holtz<[email protected]> writes:
Attached please find an updated patch.
Hi, Steve,

Looks like you attached the same patch as before by mistake; looking
forward to the updated version!

Regards,
Christian
--

Steven J Holtz
Instructor
Department of Computer Science
University of Minnesota Duluth
https://www.d.umn.edu/~sholtz/
From 96ccb992391a0de03c6ba2d9710b1076e4df2229 Mon Sep 17 00:00:00 2001
From: Steven J Holtz <[email protected]>
Date: Mon, 13 Apr 2026 16:32:54 -0500
Subject: [PATCH] Extract only selected lines from output from source code
 block.

---
 library-of-babel.org | 46 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/library-of-babel.org b/library-of-babel.org
index 2fed70e9..e3fbb5c8 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
+1
+2
+5
+7
+8
+9
+#+end_example
+
 * Misc
 
 ** File-specific Version Control logging
-- 
2.43.0

Reply via email to