
fold
kann die Zeile umbrechen, wenn sie mehr als eine bestimmte Anzahl von Zeichen enthält. Ich möchte jedoch eine Textdatei, die weniger als 40 Zeichen pro Zeile enthält, in zwei Spalten umbrechen (insgesamt 80 Zeichen pro Zeile).
ich will machen
apple
banana
(28 items omitted)
grape
guava
hinein
apple ...
banana ...
(12 items omitted) (12 items omitted)
... grape
... guava
Wie kann ich das machen?
Antwort1
Mit der Option -COLUMN
oder--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
also entweder
pr -t -2 yourfile
oder
pr -t --columns=2 yourfile
Zum Beispiel, indem Sie Ihre Einträge mit einigen zufälligen Wörtern aus dem Wörterbuch ergänzen,
$ 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
Antwort2
Sie können den Befehl aus dem Autogen-Paket verwenden columns
, zB:
columns -c 2 -w 40 --by-column < input
Zum Beispiel:
{
echo apple
echo banana
shuf -n28 /usr/share/dict/words
echo grape
echo guave
} |
columns -w 40 -c 2 --by-columns
Ausgabe:
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
Antwort3
Als Ergänzung zu Steeldrivers Antwort: Wenn Sie eine Anforderung wie meine haben, also abwechselnd Wörter in denselben Spalten drucken möchten, verwenden Sie die Option -a(across).
[user@server ~]$ cat << EOF | pr -a -t -2
> word1
> word2
> word3
> word4
> word5
> word6
> EOF
word1 word2
word3 word4
word5 word6