テキストを2列にまとめるには?

テキストを2列にまとめるには?

fold文字数が一定数を超えると改行されることがあります。しかし、1行に40文字未満のテキストファイルを2つの列(1行に合計80文字)で囲みたいです。

気づきたい

apple
banana
(28 items omitted)
grape
guava

入力する

apple                                   ...
banana                                  ...
(12 items omitted)                      (12 items omitted)
...                                     grape
...                                     guava

どうすればいいですか?

ベストアンサー1

使用-COLUMNまたは--columns=COLUMNオプションpr

-COLUMN, --columns=COLUMN
       output COLUMN columns and print columns down, unless -a is used.
       Balance number of lines in the columns on each page

だからどちらにしても

pr -t -2 yourfile

または

pr -t --columns=2 yourfile


たとえば、ランダムな辞書の単語でアイテムを展開します。

$ cat << EOF | pr -t -2
> apple
> banana
> `shuf -n28 /usr/share/dict/words`
> grape
> guava
> EOF
apple                               overachieves
banana                              wickerwork
cottonmouths                        supersonic
adapter's                           draftiest
boudoir's                           insisting
cruised                             programs
mousetrap                           parcel
shticks                             basically
TLC's                               coruscates
conduction                          Jones
geeing                              Ty
gloamings                           bondage
investing                           candelabra's
radiotherapists                     Inchon's
clasp's                             grape
critters                            guava

おすすめ記事