{"id":217,"date":"2006-11-11T16:13:43","date_gmt":"2006-11-11T14:13:43","guid":{"rendered":"http:\/\/www.lucas-nussbaum.net\/blog\/?p=217"},"modified":"2006-11-12T15:49:44","modified_gmt":"2006-11-12T13:49:44","slug":"list-operators-on-files-in-shell","status":"publish","type":"post","link":"https:\/\/www.lucas-nussbaum.net\/blog\/?p=217","title":{"rendered":"List operators on files in shell ? (updated)"},"content":{"rendered":"<p>I often need to do list-like operations on files in shell, for example:<\/p>\n<ul>\n<li>substract lines in one file from the lines in another file<\/li>\n<li>add lines from two lines, suppressing duplicates<\/li>\n<li>keep only lines which are not in both files<\/li>\n<li>keep only lines which are in both files<\/li>\n<li>etc<\/li>\n<\/ul>\n<p>Such operations are easy to do with a combination of sort, uniq, cut, diff, etc. But they are so basic operations that it is a bit annoying to write the small shell script each time I need to do one of them.<\/p>\n<p>Isn&#8217;t there a tool out there already providing all of them ?<\/p>\n<p>Also, it would be great if such operations could be achieved considering only the first <em>n<\/em> characters or words (a bit like uniq -w, or the removed uniq -W option). It would be an easy way to do :<\/p>\n<blockquote><p>i1 c1<br \/>\ni2 c2<br \/>\ni3 c3<br \/>\ni4 c4<\/p><\/blockquote>\n<p>minus<\/p>\n<blockquote><p>i2<br \/>\ni4<\/p><\/blockquote>\n<p>Comments are opened.<\/p>\n<p><strong>Update:<\/strong> many people pointed me to <a href=\"http:\/\/packages.qa.debian.org\/m\/moreutils.html\">moreutils<\/a>&#8216; combine. It looks good, bug not exactly what I need, so I filed wishlist bugs <a href=\"http:\/\/bugs.debian.org\/398187\">#398187<\/a> (combine: provide aliases for set theory operators) and <a href=\"http:\/\/bugs.debian.org\/398193\">#398193<\/a> (combine: allow to compare only on a subset of the lines). I won&#8217;t have time to provide patches, so if somebody want to work on them &#8230;. :-)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I often need to do list-like operations on files in shell, for example: substract lines in one file from the lines in another file add lines from two lines, suppressing duplicates keep only lines which are not in both files keep only lines which are in both files etc Such operations are easy to do [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"0","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,14,12,7],"tags":[],"class_list":["post-217","post","type-post","status-publish","format-standard","hentry","category-planetdebian","category-planetgnomefr","category-planetubuntu","category-technology"],"_links":{"self":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/217","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=217"}],"version-history":[{"count":0,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/217\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lucas-nussbaum.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}