How to use paste command for many files whose names are not numbers? (paste columns from each file to one file)

5,682

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:
5,682

Related videos on Youtube

Ooker
Author by

Ooker

Hi! Welcome to my profile. My work can be divided into two projects: The Sphere and A theory of perspective Project 1: The Sphere The mission of The Sphere is to promote self-refection, the respect to others, the curiosity to what causes fear, and the courage to cut harmful things. The targets are people who are suffering (or creating suffering to others), yet resist others' supports to maintain status quo. This includes abusers and people who developed a worldview to justify their learned helplessness. The method is to equip their friends and loved ones the skills and knowledge to help them change their mind. For starter, read about social work case management and consequentialism. Protectors of autonomy usually have a misconception that one's choice should always be respected, because their autonomy should always be respected. The fact is that it is only true in 99.999999% of cases, and the other 0.0000001% is people who internalized oppression. Therefore, only hoping for the best but leaving their situation intact is generally considered as undermining their autonomy. For starter, read about relational autonomy and decision-making capacity. This project is written in Vietnamese. Its website attracted ~30k people in past year (~160 on average per day). Many of them are human right activists, psychologists, religion practitioners, academic researchers, artists, etc. Project 2: A theory of perspective Imagine a floating iceberg. The part above the water is the The Sphere project. The part below the water is this project. It is to construct a theory for the concept "perspective", as in "keep a fresh perspective", "look at the problem in a new perspective", "put yourself in other's perspective", etc. The concept is intuitive, but exactly what it is is still vague. Because of that, these advices are easier said than done. The take-home message is this "formula": Challenging assumption = meaning shifting = perspective changing For more detail you can read the research proposal. You can also read the theory itself, but I should warn you that this is not a final product. Thank you for your visit, and I hope you enjoy them. Have a nice day.

Updated on September 18, 2022

Comments

  • Ooker
    Ooker over 1 year

    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
    Ooker almost 10 years
    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
    Ooker almost 10 years
    so basically there is no way to shorten my code?
  • Mathias Begert
    Mathias Begert almost 10 years
    @Ooker, see the edit
  • Ooker
    Ooker almost 10 years
    also, can you explain to me what the /%/ means?
  • Mathias Begert
    Mathias Begert almost 10 years
    @Ooker, that is used to add a suffix to every element of the MAPFILE array, for details refer this
  • Scott - Слава Україні
    Scott - Слава Україні almost 10 years
    How is $(printf "%s " $(cat list)) any better than $(cat list)? (They both fail if filenames containing whitespace are present.)