[ << ] | [ < ] | [ Up ] | [ > ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
4.5 Reverse Characters of Lines
This script can be used to reverse the position of characters in lines. The technique moves two characters at a time, hence it is faster than more intuitive implementations.
Note the tx
command before the definition of the label.
This is often needed to reset the flag that is tested by
the t
command.
Imaginative readers will find uses for this script. An example
is reversing the output of banner
.(8)
#!/usr/bin/sed -f /../! b
# Reverse a line. Begin embedding the line between two newlines s/^.*$/\ &\ /
# Move first character at the end. The regexp matches until # there are zero or one characters between the markers tx :x s/\(\n.\)\(.*\)\(.\n\)/\3\2\1/ tx
# Remove the newline markers s/\n//g
This document was generated on January 5, 2013 using texi2html 5.0.