1

I have multiple text lists, each representing a column and already in corresponding order.

i.e.

FirstName.txt:

Bob  
Sarah  
Fred  

LastName.txt

Smith  
Fulton  
Jones  

Gender.txt

Male  
Female  
Male  

Age.txt

23  
28  
31  

In BASH, how can I pull the relevant lines together to form a csv formatted entry such as..

FirstName,LastName,Gender,Age  
Bob,Smith,Male,23  
Sarah,Fulton,Female,28  
Fred,Jones,Male,31  

With thanks in advance!

2 Answers 2

7

You can use paste with comma as delimiter:

$ paste -d',' FirstName.txt LastName.txt gender.txt age.txt
Bob,Smith,Male,23
Sarah,Fulton,Female,28
Fred,Jones,Male,31

From man paste:

paste - merge lines of files

-d, --delimiters=LIST

reuse characters from LIST instead of TABs

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect! I had no idea paste existed.
It is pretty handy! As anubhava said, it is perfect for these cases.
5

That is tailor made job for paste:

paste -d',' FirstName.txt LastName.txt gender.txt age.txt
Bob,Smith,Male,23
Sarah,Fulton,Female,28
Fred,Jones,Male,31

1 Comment

Thanks so much for the quick help on this one gents. Paste is my friend.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.