# charset="CP932" # encode="CP932" # Space を Tab に #!/usr/bin/perl -wni~ # JPerl 以外では Text::Tabs use integer; BEGIN { $tabstop ||= 8; } 1 while s/^([^\t]+)(\t+)/$1 . "\x20" x (length($2) * $tabstop - length($1) % $tabstop)/em; @_ = unpack "a$tabstop" x (length($_) / $tabstop) . "a*", $_; print map(s/\x20+$/\t/, @_[0 .. -2]), ($_[-1] eq "\x20" x $tabstop) ? "\t" : $_[-1]; __END__ #!/opt/local/bin/gawk -f BEGIN { tabstop = 8; spaces = " "; } { while (match($0, /\t+/)) sub(/\t+/, substr(spaces, 1, RLENGTH * tabstop - (RSTART - 1) % tabstop)); while (length($0) > tabstop) { str = substr($0, 1, tabstop); sub(/\x20\x20+$/, "\t", str); printf "%s", str; $0 = substr($0, tabstop + 1); } print; }