1

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 locations, 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:

1MUI
2QHK
2RKF
...
Ooker
  • 667

2 Answers2

2

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    
iruvar
  • 16,725
0

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

Updated

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
cuonglm
  • 153,898