Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

To paste many files, whose names are incremental numbers:

paste {1..8}| column -s $'\t' -t
  • What if your files wasn't named by number, but only words?
  • It can be up to ten files, what should I do?

In addition, you have a list of files that contains all the files you want.

So far, my approach is:

mkdir paste
j=0; while read i; do let j+=1; cp $i/ paste/$j; done<list;
cd paste; paste {1..8}| column -s $'\t' -t

I have no problem with this approach, I just want to ask if there is any shorter one.

Actually my files have the same name, just on different direction, for instance 1MUI/PQR/A/sum, 2QHK/PQR/A/sum, 2RKF/PQR/A/sum. The paste command should be paste {list}/PQR/A/sum. The list file is:

share|improve this question
up vote 1 down vote accepted

With bash 4

mapfile -t <list
paste "${MAPFILE[@]}" | column -s $'\t' -t

for the paste {list}/PQR/A/sum version of the question

mapfile -t <list
paste "${MAPFILE[@]/%//PQR/A/sum}" | column -s $'\t' -t    
share|improve this answer
I have edited my question, sorry for the inconvenience. Please come back and see. When I use this way, the output is paste: 1MUI: Is a directory (repeat till the end of the list) and only cat one file. – Ooker Jul 9 '14 at 19:34
@Ooker, see the edit – iruvar Jul 9 '14 at 19:48
that's what I mean. Thank you. – Ooker Jul 9 '14 at 19:50
also, can you explain to me what the /%/ means? – Ooker Jul 9 '14 at 19:51
@Ooker, that is used to add a suffix to every element of the MAPFILE array, for details refer this – iruvar Jul 9 '14 at 19:52

If all your files is in single directory, just use:

paste * | column -s $'\t' -t

If you have a list file contains all files, and each file name in one line, does not have special characters like space, you can try:

paste $(printf "%s " $(cat list)) | column -s $'\t' -t


With your updated information, you can try:

paste */PQR/A/sum | column -s $'\t' -t

If your parent directory contains many files and directory that you don't need, you must list all your directory explicitly:

paste {1MUI,2QHK,2RKF,...}/PQR/A/sum | column -s $'\t' -t
share|improve this answer
wow, you update your answer before I comment. Thanks a lot. Nevertheless, my folder contains more files and folders which don't relevant to my need, therefore I can't use *. – Ooker Jul 9 '14 at 19:31
so basically there is no way to shorten my code? – Ooker Jul 9 '14 at 19:43
How is $(printf "%s " $(cat list)) any better than $(cat list)? (They both fail if filenames containing whitespace are present.) – Scott Jul 11 '14 at 18:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.