Bash、sed: 228 223 197 (242-70)= 172
c=${5:-=};R=$c;L=;for f in r l;do
e="sed -e ";$e"$ d;s/$\| */ \n/g" $1>m
o=1;for w in `$e"$ p;d" $1`;do
$e"$o,/^$w /s/^$w /$L$w$R /" m>n;o="/$c/"
cp n m;done;tr -d \\n<n|fold -sw${2:-35}|$e"s/$c/ /g">$f
L=$c;R=;done;pr -tmw${3:-80} ${4:-l r}
スクリプトが「ステレオ」と呼ばれる実行可能ファイルにある場合は、次を入力します。
stereo file.in [column_width [page_width ["r l"]]]
column_widthは数値です。25〜45が機能し、デフォルトは35です。
page_widthは数値で、column_widthの約2倍で、デフォルトは80です
寄り目で見るには、4番目の引数として「r l」を使用します。デフォルトは「l r」で、並列表示用に設定されています。
編集:ファイルを1行に1ワードに分割して書き直し、最後に再構築します。注:独自の使用のために「=」記号を予約します。入力ファイル内の「=」記号は空白になります。
編集:メッセージに「=」記号が含まれている場合、5番目のパラメーターとして指定することで、スクリプトが使用する別の記号を選択できます。
例
入力:vegetarianism.txt:
I invented vegetarianism. It is a diet involving no meat, just
vegetables. It is also common in cows - they are awesome.
vegetarianism. is awesome.
結果
./stereo vegetarianism.txt 32 72 "l r":| 展開(内部作業シンボルにコロンを使用)
I invented vegetarianism. It I invented vegetarianism. It
is a diet involving no meat, is a diet involving no meat,
just vegetables. It is also just vegetables. It is also
common in cows - they are common in cows - they are
awesome. awesome.
./stereo washington.txt 35 75 "l r" |展開
In a little district west of In a little district west of
Washington Square the streets Washington Square the streets
have run crazy and broken have run crazy and broken
themselves into small strips themselves into small strips
called 'places'. These 'places' called 'places'. These 'places'
make strange angles and curves. make strange angles and curves.
One Street crosses itself a time One Street crosses itself a time
or two. An artist once discovered or two. An artist once discovered
a valuable possibility in this a valuable possibility in this
street. Suppose a collector with a street. Suppose a collector with a
bill for paints, paper and canvas bill for paints, paper and canvas
should, in traversing this route, should, in traversing this route,
suddenly meet himself coming suddenly meet himself coming
back, without a cent having been back, without a cent having been
paid on account! paid on account!
「| expand」は必要ありませんが、出力を4桁シフトすると、TABが正しく処理されません。7バイトのコストでスクリプトに挿入できます。
ImageMagickバリエーション
最後の行をテキストからイメージへのImageMagickコマンドで置き換える:
c=${6:-=};R=$c;L=;for f in r l;do
e="sed -e ";$e"$ d;s/$\| */ \n/g" $1>m
o=1;for w in `$e"$ p;d" $1`;do
$e"$o,/^$w /s/^$w /$L$w$R /" m>n;o="/$c/"
cp n m;done;tr -d \\n<n|fold -sw${2:-35}|$e"s/$c/ /g">$f
L=$c;R=;done;
convert -border 10x30 label:@${4:-l} label:@${5:-r} +append show:
この1つでは、寄り目と並列表示の「r」と「l」は別々の引数です。
./im_stereo vegetarianism.txt 40 80 lr =
(ソース:simplesystems.org)
編集3:ImageMagickバリエーションを追加しました。