Combining several files into a single CSV

5,841

Solution 1

With paste:

paste 1.txt 2.txt 3.txt

The output is:

1       Apple   55
2       Mango   100
3       Orange  30

Solution 2

To create a csv file, you can do it like this (setting the delimiter to a comma) :

paste -d"," 1.txt 2.txt 3.txt >> example.csv
Share:
5,841

Related videos on Youtube

Gautam
Author by

Gautam

Updated on September 18, 2022

Comments

  • Gautam
    Gautam over 1 year

    Input files:

    File: 1.txt:

    1
    2
    3
    

    File: 2.txt:

    Apple
    Mango
    Orange
    

    File: 3.txt:

    55
    100
    30
    

    Desired Output:

    File: example.csv:

    column1   column2   column3
    1         Apple     55
    2         Mango     100
    3         Orange    30
    
  • chaos
    chaos over 8 years
    Along with the fact that it's nearly the same answer as mine, it pastes the ouput together with a comma, not with tabs.
  • Yedric
    Yedric over 8 years
    Question specified CSV, which REQUIRES commas.
  • Yedric
    Yedric over 8 years
    Question specified CSV, which REQUIRES commas. Answer is missing commas.
  • chaos
    chaos over 8 years
    @Yedric This is nowhere mentioned, the example output shows clearly tabs...
  • Yedric
    Yedric over 8 years
    the title says CSV. I assumed that the output example was shown with separated columns for clarity.
  • Gautam
    Gautam over 8 years
    Hi dudes, Thanks for your replies. Is it possible to copy these txt files as required previously in the 3 rd sheet in csv file? Look forward for your valuable reply.