{"id":526,"date":"2009-01-09T19:05:22","date_gmt":"2009-01-09T18:05:22","guid":{"rendered":"http:\/\/www.walkingrandomly.com\/?p=526"},"modified":"2009-01-09T19:05:22","modified_gmt":"2009-01-09T18:05:22","slug":"joining-files-together-line-by-line-in-linux","status":"publish","type":"post","link":"https:\/\/walkingrandomly.com\/?p=526","title":{"rendered":"Joining files together line by line in Linux"},"content":{"rendered":"<p>Say you have a file called alpha.txt that contains<br \/>\n<code><br \/>\na<br \/>\nb<br \/>\nc<br \/>\n<\/code><br \/>\nand another file called numbers.txt that contains<br \/>\n<code><br \/>\n1<br \/>\n2<br \/>\n3<br \/>\n<\/code><br \/>\nand you want to concatenate them together such that the resulting file reads<br \/>\n<code><br \/>\na\t1<br \/>\nb\t2<br \/>\nc\t3<br \/>\n<\/code><br \/>\nOf course this is a fairly trivial thing to do in any number of programming languages but I believe in <strong>not<\/strong> programming anything if I can possibly get away with it.  With that in mind here is a standard Linux command (included in Ubuntu at least but probably in most other versions of Linux as well) that will do this for you.<br \/>\n<code><br \/>\npaste alpha.txt nums.txt > joined.txt<br \/>\n<\/code><br \/>\nBy default, the paste command separates fields by tabs but you can easily change this with the -d switch.  For example<br \/>\n<code><br \/>\npaste alpha.txt num.txt -d , > joined.txt<br \/>\n<\/code><br \/>\nresults in a comma separated value (CSV) file<br \/>\n<code><br \/>\na,1<br \/>\nb,2<br \/>\nc,3<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Say you have a file called alpha.txt that contains a b c and another file called numbers.txt that contains 1 2 3 and you want to concatenate them together such that the resulting file reads a 1 b 2 c 3 Of course this is a fairly trivial thing to do in any number of [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[5],"tags":[],"class_list":["post-526","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p3swhs-8u","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/526","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=526"}],"version-history":[{"count":3,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions"}],"predecessor-version":[{"id":529,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=\/wp\/v2\/posts\/526\/revisions\/529"}],"wp:attachment":[{"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=526"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=526"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/walkingrandomly.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=526"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}