Aloha all,

The patch follows inline.

Let me know if you have questions.

All the best,
Tom

>From 8ba07bfffc350105a2a5d02939d207dfe833d970 Mon Sep 17 00:00:00 2001
From: "Thomas S. Dye" <tsd@tsdye.online>
Date: Sun, 17 Aug 2025 16:39:22 -1000
Subject: [PATCH] Add ob-doc-sed.org.

Also, put a link in the language table of index.org.
---
 org-contrib/babel/languages/index.org      |   2 +-
 org-contrib/babel/languages/ob-doc-sed.org | 165 +++++++++++++++++++++
 2 files changed, 166 insertions(+), 1 deletion(-)
 create mode 100644 org-contrib/babel/languages/ob-doc-sed.org

diff --git a/org-contrib/babel/languages/index.org b/org-contrib/babel/languages/index.org
index aeed3f4c..0760e888 100644
--- a/org-contrib/babel/languages/index.org
+++ b/org-contrib/babel/languages/index.org
@@ -123,7 +123,7 @@ Note that there are some [[file:lang-compat.org][inconsistencies among supported
 | [[https://www.gnu.org/software/gforth/][Gforth]]        | =forth=               | [[file:ob-doc-forth.org][ob-doc-forth]]         |                   |
 | [[http://www.gnuplot.info/][Gnuplot]]       | =gnuplot=             | [[file:ob-doc-gnuplot.org][ob-doc-gnuplot]]       | Ihor Radchenko    |
 | [[https://www.gnu.org/software/screen/][GNU Screen]]    | =screen=              | [[file:ob-doc-screen.org][ob-doc-screen]]        | Ken Mankoff       |
-| [[https://www.gnu.org/software/sed/][GNU sed]]       | =sed=                 |                      |                   |
+| [[https://www.gnu.org/software/sed/][GNU sed]]       | =sed=                 | [[file:ob-doc-sed.org][ob-doc-sed]]           |                   |
 | [[http://www.graphviz.org/][Graphviz]]      | =dot=                 | [[file:ob-doc-dot.org][ob-doc-dot]]           | Justin Abrahms    |
 | [[http://www.haskell.org/][Haskell]]       | =haskell=             |                      | Lawrence Bottorff |
 | [[https://openjdk.java.net/][Java]]          | =java=                | [[file:ob-doc-java.org][ob-doc-java]]          | Ian Martins       |
diff --git a/org-contrib/babel/languages/ob-doc-sed.org b/org-contrib/babel/languages/ob-doc-sed.org
new file mode 100644
index 00000000..78c68cce
--- /dev/null
+++ b/org-contrib/babel/languages/ob-doc-sed.org
@@ -0,0 +1,165 @@
+# #+OPTIONS:    H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc broken-links:nil
+#+STARTUP:    align fold nodlcheck hidestars oddeven lognotestate hideblocks
+#+SEQ_TODO:   TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
+#+TAGS:       Write(w) Update(u) Fix(f) Check(c) noexport(n)
+#+TITLE:      sed Code Blocks in Babel
+#+AUTHOR:     Thomas S. Dye
+#+EMAIL:      tsd[at]tsdye[dot]online
+#+LANGUAGE:   en
+#+HTML_LINK_UP:    index.html
+#+HTML_LINK_HOME:  https://orgmode.org/worg/
+#+EXCLUDE_TAGS: noexport
+
+#+name: banner
+#+begin_export html
+  <div id="subtitle" style="float: center; text-align: center;">
+  <p>
+  Babel support for <a href="https://www.gnu.org/software/sed/";>sed</a>
+  </p>
+  <p>
+  <a href="https://9p.io/magic/man2html/1/sed";>sed -- stream-editor</a>
+  </p>
+  </div>
+#+end_export
+
+* Template Checklist [11/12]                                       :noexport:
+  - [X] Revise #+TITLE:
+  - [X] Indicate #+AUTHOR:
+  - [X] Add #+EMAIL:
+  - [X] Revise banner source block [3/3]
+    - [X] Add link to a useful language web site
+    - [X] Replace "Language" with language name
+    - [X] Find a suitable graphic and use it to link to the language
+      web site
+  - [X] Write an [[Introduction]]
+  - [X] Describe [[Requirements and Setup][Requirements and Setup]]
+  - [X] Replace "Language" with language name in [[Org Mode Features for Language Source Code Blocks][Babel Features for Language Source Code Blocks]]
+  - [X] Describe [[Header Arguments][Header Arguments]]
+  - [X] Describe support for [[Sessions]]
+  - [X] Describe [[Result Types][Result Types]]
+  - [X] Describe [[Other]] differences from supported languages
+  - [ ] Provide brief [[Examples of Use][Examples of Use]]
+* Introduction
+
+The Unix utility =sed= (stream editor) is a non-interactive
+command-line text editor that can be used to filter text in order to
+extract part of a file or to substitute multiple occurrences of a
+string in a file.
+
+Alternatives to =sed= include =awk= and =Perl=.
+
+* Requirements and Setup
+
+The =sed= utility was created more than 50 years ago and is currently available on most operating systems.
+
+To enable Babel evaluation of =sed= code blocks, add a sexp to
+=org-babel-load-languages= as follows:
+
+#+begin_example
+(org-babel-do-load-languages
+ 'org-babel-load-languages
+ '((sed . t))) ;; this line configures Babel =sed= support
+#+end_example
+
+* Babel Features for sed Code Blocks
+** Header Arguments
+There are no =sed=-specific default values for header arguments.
+
+There are two =sed=-specific header arguments.  The header argument =:cmd-line= can be used to pass command line arguments to =sed=.  The header argument :in-file can be used to specify the input file for =sed=.
+
+** Sessions
+
+The =sed= utility is non-interactive and does not support sessions.
+
+** Result Types
+
+By default, a =sed= code block returns a table.  This behavior can be changed with header arguments or by passing command line arguments to =sed=.
+
+* Examples of Use
+
+The examples all use this input file:
+
+#+begin_example
+one two three, one two three
+four three two one
+one hundred
+#+end_example
+
+By default, =sed= code blocks return a table.
+
+#+begin_example
+,#+name: sed_default
+,#+begin_src sed :in-file ~/temp/sed-test.txt
+s/one/ONE/g
+,#+end_src
+
+,#+RESULTS: sed_default
+| ONE  | two     | three, | ONE | two | three |
+| four | three   | two    | ONE |     |       |
+| ONE  | hundred |        |     |     |       |
+#+end_example
+
+The header argument =:results verbatim= returns the contents of the filtered input.
+
+#+begin_example
+,#+name: sed_return
+,#+begin_src sed :in-file ~/temp/sed-test.txt :results verbatim
+s/one/ONE/g
+,#+end_src
+
+,#+RESULTS: sed_return
+: ONE two three, ONE two three
+: four three two ONE
+: ONE hundred
+#+end_example
+
+Command line arguments to =sed= can be passed with the header argument =:cmd-line=.
+
+#+begin_example
+,#+name: sed_silent
+,#+begin_src sed :in-file ~/temp/sed-test.txt :results verbatim :cmd-line -n
+s/one/ONE/g
+,#+end_src
+
+,#+RESULTS: sed_silent
+#+end_example
+
+Here is the obligatory 'Hello, world!' example.
+
+#+begin_example
+,#+name: sed_hello
+,#+begin_src sed  :in-file ~/temp/sed-test.txt :results verbatim
+# convert input text stream to "Hello, world!"
+s/.*/Hello, world!/
+q
+,#+end_src
+
+,#+RESULTS: sed_hello
+: Hello, world!
+#+end_example
+
+The output from =sed= can be directed to a file with the header arguments =:file= and, optionally =:output-dir=.  The header argument =:results file= inserts a link to the output file in the Org mode buffer.
+
+Note the comment on the first line of the code block. Note also the last line, which instructs =sed= to quit.
+
+#+begin_example
+,#+name: sed_file
+,#+begin_src sed  :in-file ~/temp/sed-test.txt :results file :file sed-results.txt :output-dir ~/temp/
+# convert input text stream to "Hello, world!"
+s/.*/Hello, world!/
+q
+,#+end_src
+
+,#+RESULTS: sed_file
+[[file:~/temp/sed-results.txt]]
+#+end_example
+
+The file =sed-results.txt= looks like this:
+
+#+begin_example
+Hello, world!
+#+end_example
+
+* Links
+
+Preparation of this documentation was aided by [[https://www.grymoire.com/Unix/Sed.html#toc_Sed_-_An_Introduction_and_Tutorial_by_Bruce_Barnett][Bruce Barnett's introduction and tutorial]].
-- 
2.34.1


--
Thomas S. Dye
https://tsdye.online/tsdye

Reply via email to