Skip to content

Instantly share code, notes, and snippets.

@yoggy
Last active October 4, 2017 13:09
Show Gist options
  • Save yoggy/94e939f29b952a4d7c3e733a73453fd6 to your computer and use it in GitHub Desktop.
Save yoggy/94e939f29b952a4d7c3e733a73453fd6 to your computer and use it in GitHub Desktop.
$ cat a.txt
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
cccccccccccccccccccccccccccccccccccccccccccccccccc
あああああああああああああああああああああああああああああああ
いいいいいいいいいいいいいいいいいいいい
うううううううううううううう
123123123123123123123123123123123123
$ cat a.txt | ruby -ple 'l="";n=0;$_.each_char{|c|l+=c;n+=(c.ord<128?1:2);if(n>40) then n=0;l+="\n" end};$_=l'
8
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaa
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
bbb
ccccccccccccccccccccccccccccccccccccccccc
ccccccccc
あああああああああああああああああああああ
ああああああああああ
いいいいいいいいいいいいいいいいいいいい
うううううううううううううう
1231231231231231231231231231
23123123
@yoggy
Copy link
Author

yoggy commented Oct 4, 2017

vimだと、外部コマンドをフィルタとして使う方法と組み合わせると吉。
↓は範囲指定後、外部コマンドを起動して指定した範囲内の文字列を整形している例。

vim

参考 : http://nanasi.jp/articles/howto/editing/external-program.html#id5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment