Service to underline plain text with a line of dashes

I am looking for a text service that I can call from a plain text editor (BBedit for example) and will operate the following modification:

Before:

This is a line of text

After:

This is a line of text
----------------------

Thanks !


Solution 1:

BBedit can execute shell commands on selected text, so adapting something like

echo 'This is a line of text' | sed -n 'p;s/./-/gp'

to make it work when called from BBedit should work.

  • sed -n runs sed without echoing its input automatically
  • p is the first command applied to the input, it just prints the input (technically the content of the pattern space)
  • s/./-/gp is the second command, it replaces all characters in the pattern space by - and prints the result