How to paste columns from separate files using bash?

后端 未结 4 1772
醉酒成梦
醉酒成梦 2020-12-03 04:22

Using the following data:

$cat date1.csv
 Bob,2013-06-03T17:18:07
 James,2013-06-03T17:18:07
 Kevin,2013-06-03T17:18:07

$cat date2.csv
 2012-12-02T18:30:31
         


        
4条回答
  •  我在风中等你
    2020-12-03 04:57

    You were on track with paste(1):

    $ paste -d , date1.csv date2.csv 
    Bob,2013-06-03T17:18:07,2012-12-02T18:30:31
    James,2013-06-03T17:18:07,2012-12-02T18:28:37
    Kevin,2013-06-03T17:18:07,2013-06-01T12:16:05
    

    It's a bit unclear from your question if there are leading spaces on those lines. If you want to get rid of that in the final output, you can use cut(1) to snip it off before pasting:

     $ cut -c 2- date2.csv | paste -d , date1.csv -
      Bob,2013-06-03T17:18:07,2012-12-02T18:30:31
      James,2013-06-03T17:18:07,2012-12-02T18:28:37
      Kevin,2013-06-03T17:18:07,2013-06-01T12:16:05
    

提交回复
热议问题