{"id":60,"date":"2018-09-20T18:16:02","date_gmt":"2018-09-20T22:16:02","guid":{"rendered":"http:\/\/sites.nd.edu\/crivaldi\/?p=60"},"modified":"2019-11-05T14:47:20","modified_gmt":"2019-11-05T18:47:20","slug":"string-manipulation-with-sed-and-grep","status":"publish","type":"post","link":"https:\/\/sites.nd.edu\/crivaldi\/2018\/09\/20\/string-manipulation-with-sed-and-grep\/","title":{"rendered":"String manipulation with sed and grep"},"content":{"rendered":"<p><em>*Note to all users: As of 07\/14\/2019, all posts have been moved to (and are being updated at <a href=\"https:\/\/crivaldi.github.io\">crivaldi.github.io . <\/a>I don&#8217;t have plans to shut this site down, but I have no idea how long it will be maintained by the university in the future.*<\/em><\/p>\n<h1>String manipulation with sed and grep<\/h1>\n<p>What is string manipulation and why do we care about this?<\/p>\n<p>As biologists, or more generally as people interested in working with data, a lot of what we want to do will require us to manipulate many characters at the same time.<\/p>\n<p>By definition:<\/p>\n<ul>\n<li>A <strong>character<\/strong> is\u00a0 class whose instances can hold a single character value.<\/li>\n<li>A <strong>string <\/strong> is an <i>immutable<\/i> class for working with multiple characters.<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p>For our purposes, we can consider strings as information that we don&#8217;t want to use for numerical calculations. DNA sequences, column or row names, and categorical\/qualitative data values will generally be strings. You might want to remove the primers from a lot (like <em>a lot<\/em>) of sequences at the same time, or you might want to remove whitespaces from a dataset you found online.<\/p>\n<p>Most of our string manipulation is covered by the previous links that are tied in with the for loops &#8211; here are a couple of useful comics for some of those commands though. &#8216;awk&#8217; is new but you&#8217;re probably going to run into it during google adventures. As it in some ways is its own programming language, it&#8217;s very much worth learning, we just didn&#8217;t quite have time to fit it into our classwork.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-65 size-full\" src=\"http:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/awk.jpg\" alt=\"\" width=\"1494\" height=\"958\" srcset=\"https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/awk.jpg 1494w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/awk-300x192.jpg 300w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/awk-768x492.jpg 768w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/awk-1024x657.jpg 1024w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-61 size-full\" src=\"http:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/sed.jpg\" alt=\"\" width=\"1168\" height=\"752\" srcset=\"https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/sed.jpg 1168w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/sed-300x193.jpg 300w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/sed-768x494.jpg 768w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/sed-1024x659.jpg 1024w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-62 size-full\" src=\"http:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/grep.jpg\" alt=\"\" width=\"1200\" height=\"756\" srcset=\"https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/grep.jpg 1200w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/grep-300x189.jpg 300w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/grep-768x484.jpg 768w, https:\/\/sites.nd.edu\/crivaldi\/files\/2018\/09\/grep-1024x645.jpg 1024w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p><a href=\"https:\/\/www.hackerearth.com\/practice\/algorithms\/string-algorithm\/basics-of-string-manipulation\/tutorial\/\">https:\/\/www.hackerearth.com\/practice\/algorithms\/string-algorithm\/basics-of-string-manipulation\/tutorial\/<\/a><\/p>\n<p><a href=\"https:\/\/pythonforbiologists.com\/printing-and-manipulating-text\/\">https:\/\/pythonforbiologists.com\/printing-and-manipulating-text\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>*Note to all users: As of 07\/14\/2019, all posts have been moved to (and are being updated at crivaldi.github.io . I don&#8217;t have plans to shut this site down, but I have no idea how long it will be maintained by the university in the future.* String manipulation with sed and grep What is string &hellip; <a href=\"https:\/\/sites.nd.edu\/crivaldi\/2018\/09\/20\/string-manipulation-with-sed-and-grep\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;String manipulation with sed and grep&#8221;<\/span><\/a><\/p>\n","protected":false},"author":2790,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[29880],"tags":[],"class_list":["post-60","post","type-post","status-publish","format-standard","hentry","category-unix"],"_links":{"self":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/60","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/users\/2790"}],"replies":[{"embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/comments?post=60"}],"version-history":[{"count":8,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/60\/revisions"}],"predecessor-version":[{"id":175,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/posts\/60\/revisions\/175"}],"wp:attachment":[{"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/media?parent=60"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/categories?post=60"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sites.nd.edu\/crivaldi\/wp-json\/wp\/v2\/tags?post=60"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}