Package: sedsed
sedsedDebugger and code formatter for sed scripts, by Aurelio Jargas.Website:https://aurelio.net/projects/sedsed/Download / InstallSedsed is available as a pip package, just install it:pip install --user sedsedCompatible with Python 2.7 and Python 3.xLicense: GPLv3Released versionsCHANGELOG.mdfor the list of changes in each versionAlternative: sedsed is a single file application, so you can also just download and runsedsed.py. Note that you'll also need to download its only external requirement,sedparse.py.Code formatting for sed scriptsSedsed can turn cryptic oneliners into readable indented code:$sedsed--indent':a;s/<[^>]*>//g;/</{N;ba;}':as/<[^>]*>//g/</ {Nb a}Convert your script to HTML to get code formatting, beautiful syntax highlighting and clickable links for GOTO commands (bandt).$sedsed--htmlize-fmyscript.sed>myscript.htmlSee many examples of HTML-converted scripts inhttp://sed.sourceforge.net/local/scripts/Debugging sed scriptsSedsed allows you to debug your sed scripts. It inserts extra sed commands into the script and uses the system's sed to execute the modified script.The added commands won't affect the script's original logic, but will show debug information while sed is running the script: the current command is printed, as well as the contents of bothPATTERN SPACEandHOLD SPACEbuffers, before and after every command.With that information at hand, you can see how sed operates under the curtains.For example, compare the normal sed run and the sedsed debug run for a script to reverse the line order (similar to Unixtac):$ echo -e 'A\nB\nC' | sed '1!G;h;$!d'
C
B
A$ echo -e 'A\nB\nC' | sedsed --debug '1!G;h;$!d'
PATT:A$
HOLD:$
COMM:1 !G
PATT:A$
HOLD:$
COMM:h
PATT:A$
HOLD:A$
COMM:$ !d
PATT:B$
HOLD:A$
COMM:1 !G
PATT:B\nA$
HOLD:A$
COMM:h
PATT:B\nA$
HOLD:B\nA$
COMM:$ !d
PATT:C$
HOLD:B\nA$
COMM:1 !G
PATT:C\nB\nA$
HOLD:B\nA$
COMM:h
PATT:C\nB\nA$
HOLD:C\nB\nA$
COMM:$ !d
PATT:C\nB\nA$
HOLD:C\nB\nA$
C
B
AThe input is three lines A, B and C, and the output is those three lines reversed: C, B, A. You can see how the sed buffers (PATTandHOLD) changed after every command (COMM).Another example, a script to remove all HTML tags. It even removes tags that span in multiple lines.$ cat menu.html
<a
   class="menu"
   href="index.html">Home</a>$ cat menu.html | sed -e ':a;s/<[^>]*>//g;/</{N;ba;}'
Home$ cat menu.html | sedsed --debug --hide=hold -e ':a;s/<[^>]*>//g;/</{N;ba;}'
PATT:<a$
COMM::a
COMM:s/<[^>]*>//g
PATT:<a$
COMM:/</ {
COMM:N
PATT:<a\n   class="menu"$
COMM:b a
COMM:s/<[^>]*>//g
PATT:<a\n   class="menu"$
COMM:/</ {
COMM:N
PATT:<a\n   class="menu"\n   href="index.html">Home</a>$
COMM:b a
COMM:s/<[^>]*>//g
PATT:Home$
COMM:/</ {
PATT:Home$
HomeYou can see in thePATTlines how the multiline<a>tag is accumulated before thescommand can remove the whole tag at once, leaving only its contents:Home.Note that the--hide=holdoption was used to avoid showing the contents of theHOLD SPACEbuffer. It would be empty all the way, since this script does not use that extra buffer. You can also hide thePATTandCOMMlines, if necessary.For tricky scripts, sometimes it helps to only see the contents of thePATTERN SPACEbuffer changing, so you can get a sense of how it is manipulated during execution. Using--hide=hold,commyou can achieve that. The next example uses that to show how ABC turned into CBA in this nice script to reverse strings (similar to Unixrev):$ echo ABC | sedsed --debug --hide=hold,comm \
    -e '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//' | uniq
PATT:ABC$
PATT:ABC\n$
PATT:ABC\nBC\nA$
PATT:BC\nA$
PATT:BC\nC\nBA$
PATT:C\nBA$
PATT:C\n\nCBA$
PATT:\nCBA$
PATT:CBA$
CBAIn those examples the sed script was informed as an argument using the-eoption. Sedsed also supports the-foption to inform a sed script file, and the traditional-noption to run in quiet mode.Enjoy!