I have a textfile like:
Adam
Bob
Cevin
David
Evan
If I "paste - -" it, I get:
Adam Bob
Cevin David
Evan
But I need that the lower half will be added as a new column:
Adam David
Bob Evan
Cevin
Is there a easy way to do this?
I have a textfile like:
Adam
Bob
Cevin
David
Evan
If I "paste - -" it, I get:
Adam Bob
Cevin David
Evan
But I need that the lower half will be added as a new column:
Adam David
Bob Evan
Cevin
Is there a easy way to do this?
You could use:
pr -t -2 file
Beware it truncates the lines that are wider than half the page width (72 characters by default, see the -w option to change it).
(note that with the GNU implementation, the column alignment may be off if the file contains multi-byte or zero-width or double-width characters). Or:
pr -t -2 -s file
to separate the columns with one tab character like paste does (there's no truncation then).
Note however that pr treats the form-feed character (^L) as a page delimiter. Not a problem if that character is not present in your file.
Or with zsh:
print -r -C2 -- ${(f)"$(<file)"}
$(<file): grab the content of file(f): split it on linefeed (newline) characters-r: print raw-C2: on 2 Columns.pr and couldn't find where it accepts a number after -t... would you tell me? I always find man pages difficult. thanks!
-t, that's the -2 option. -COLUMN, --columns=COLUMN in the GNU pr man page. I'll break the -t2 down in the answer to avoid confusion.
pr, but a non-GNU implementation?
pr from the heirloom toolchest which seems to work OK.