次: tac, 前: Print bash environment, 上: Examples
以下のスクリプトは,行の文字の位置を反転するために使用することが可能で す.二つの文字を同時に移動するテクニックで,直観的な実装より高速になり ます.
ラベル定義の前のtx
コマンドに注意してください.これはt
コマ
ンドでテストされるフラグをリセットするために必要になることがよくありま
す.
想像力豊かな読者は,このスクリプトの使い方が分かるでしょう.例えば,
banner
の出力を反転させることです1
#!/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
[1] これは,banner
の出力を埋める他のスクリプトが必要です.例えば以下のようにします.
#! /bin/sh banner -w $1 $2 $3 $4 | sed -e :a -e '/^.\{0,'$1'\}$/ { s/$/ /; ba; }' | ~/sedscripts/reverseline.sed