
fold
一定以上の文字数がある場合、行を折り返すことができます。ただし、各行の文字数が 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
答え2
columns
autogen パッケージのコマンドを使用できます。例:
columns -c 2 -w 40 --by-column < input
例えば:
{
echo apple
echo banana
shuf -n28 /usr/share/dict/words
echo grape
echo guave
} |
columns -w 40 -c 2 --by-columns
出力:
apple merwoman
banana chiroplasty
antispreading stylommatophorous
spearmint Sphaerobolaceae
sulphoxyphosphate snark
nymphaeum reactionary
ahluwalia hobo
husky oxamethane
crimeproof deltarium
cerebrosis hematoporphyrin
yoghurt noncompoundable
colloquial sororially
unaffirmed nonobjection
saccharated reundercut
thermochemic grape
preobedience guave
答え3
Steeldriver さんの回答に加えて、私のような要件、つまり同じ列に交互に単語を印刷する必要がある場合は、-a(across) オプションを使用してください。
[user@server ~]$ cat << EOF | pr -a -t -2
> word1
> word2
> word3
> word4
> word5
> word6
> EOF
word1 word2
word3 word4
word5 word6