텍스트를 두 개의 열로 묶으려면 어떻게 해야 합니까?

텍스트를 두 개의 열로 묶으려면 어떻게 해야 합니까?

fold특정 문자 수보다 많은 경우 줄을 줄 바꿈할 수 있습니다. 그러나 각 줄에 40자 미만의 텍스트 파일을 두 개의 열(줄당 총 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

columnsautogen 패키지의 명령을 사용할 수 있습니다 . 예:

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

관련 정보