How to implement a horizontal cat?
This sounds like a job for paste:
paste -d ' ' a.dat 1.dat
Output:
a b 1 2
c d 3 4
Related videos on Youtube
Konrad Rudolph
I’m a bioinformatician/scientist & software developer. I hold a PhD from the University of Cambridge and EMBL-EBI. I’ve dabbled in everything from biological research (mostly genomics and epigenetics) and statistical analysis (using R) to software development, both on the frontend (using e.g. HTML, JavaScript, WinForms, Swing) and the backend (using C++, Java, Python, Ruby, PHP, to name a few). [he/him] 💜 Sponsor me on GitHub if you would like to support what I’m doing here.
Updated on September 18, 2022Comments
-
Konrad Rudolph almost 2 years
Standard
cat
concatenates files line by line (row by row, if you will). I find myself needing a horizontalcat
command more and more often recently; i.e. a command that takes a list of files and concatenates them horizontally, column by column. So far I’ve used ad-hoc workarounds but I’d like to know if there exists a good solution for this.To clarify, consider the following comparison between
cat
andhcat
of two files:$ cat a.dat 1.dat a b c d 1 2 3 4 $ hcat -s ' ' a.dat 1.dat a b 1 2 c d 3 4
(Unlike for
cat
we need to specify a separator since by convention UNIX files don’t have a column separator at the end.) -
Konrad Rudolph over 11 yearsPerfect, thanks. That was easier than anticipated.