{"id":1782,"date":"2013-12-11T15:38:23","date_gmt":"2013-12-11T15:38:23","guid":{"rendered":"http:\/\/blog.designed79.co.uk\/?p=1782"},"modified":"2013-12-11T15:38:23","modified_gmt":"2013-12-11T15:38:23","slug":"trimming-white-space-with-sed","status":"publish","type":"post","link":"https:\/\/blog.designed79.co.uk\/?p=1782","title":{"rendered":"Trimming White Space with Sed"},"content":{"rendered":"<p>You can use the following sed commands to trim white space from lines of text:<\/p>\n<p>Trim white space from both sides of a string<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">echo ' abc ' | sed 's\/^ *\/\/;s\/ *$\/\/'<\/div><\/div>\n<p>Trim white space from the right of a string<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">echo ' abc ' | sed 's\/*\/\/;s\/ *$\/\/'<\/div><\/div>\n<p>Trim white space from the left of a string<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">echo ' abc ' | sed 's\/^ *\/\/;s\/$\/\/'<\/div><\/div>\n<p>Trim white space from both ends of every line in a file (keeping a .bak backup)<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">sed -i.bak 's\/^ *\/\/;s\/ *$\/\/' file.txt<\/div><\/div>\n<p>Trim white space from both ends of every line of every file in the current directory (keeping a .bak backup)<\/p>\n<div class=\"codecolorer-container text default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">ls -1 | while read line; do cat $line | sed -i.bak 's\/^ *\/\/;s\/ *$\/\/' $line<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>You can use the following sed commands to trim white space from lines of text: Trim white space from both sides of [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1782","post","type-post","status-publish","format-standard","hentry","category-info-on-tech"],"_links":{"self":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1782","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1782"}],"version-history":[{"count":0,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/1782\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1782"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1782"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.designed79.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1782"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}