{"id":3737,"date":"2016-01-26T17:13:02","date_gmt":"2016-01-26T17:13:02","guid":{"rendered":"https:\/\/blog.ed.gs\/?p=3737"},"modified":"2020-11-04T11:01:04","modified_gmt":"2020-11-04T11:01:04","slug":"macos-sed-invalid-command-code","status":"publish","type":"post","link":"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/","title":{"rendered":"MacOS sed “Invalid Command Code”"},"content":{"rendered":"

The version of sed that is shipped with OS X\/MacOS is different to that of most Linux distros in such that you have to issue an extra few characters to get it to do the same command.<\/p>\n

If you do the following you will result in a “invalid command code” error when trying to delete line 39 of filenamehere.log:<\/p>\n

sed -i 39d filenamehere.log<\/pre>\n

The OS X\/MacOS version needs a value for the -i flag so you don’t inadvertently overwrite a file if you don’t mean to. To overwrite the file we’re trying to modify you just need to add two speech marks after the -i flag as follows.<\/p>\n

sed -i "" 39d filenamehere.log<\/pre>\n

If you wanted to save a new file before overwriting the old one, you’d do the following:<\/p>\n

sed -i "filename.log.bak" 39d filenamehere.log<\/pre>\n","protected":false},"excerpt":{"rendered":"

The version of sed that is shipped with OS X\/MacOS is different to that of most Linux distros in such that you have to issue an extra few characters to get it to do the same command. If you do the following you will result in a “invalid command code” error when trying to delete […]<\/p>\n","protected":false},"author":2,"featured_media":3840,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[32,41,201,48],"tags":[],"yoast_head":"\nMacOS sed "Invalid Command Code" - E<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MacOS sed "Invalid Command Code" - E\" \/>\n<meta property=\"og:description\" content=\"The version of sed that is shipped with OS X\/MacOS is different to that of most Linux distros in such that you have to issue an extra few characters to get it to do the same command. If you do the following you will result in a “invalid command code” error when trying to delete […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2016-01-26T17:13:02+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-11-04T11:01:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2016\/01\/gratisography-346H.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"2048\" \/>\n\t<meta property=\"og:image:height\" content=\"1365\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ed\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ed\" \/>\n\t<meta name=\"twitter:label2\" content=\"Estimated reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/\",\"url\":\"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/\",\"name\":\"MacOS sed \\\"Invalid Command Code\\\" - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2016-01-26T17:13:02+00:00\",\"dateModified\":\"2020-11-04T11:01:04+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/\"]}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/ed.gs\/#website\",\"url\":\"https:\/\/ed.gs\/\",\"name\":\"E\",\"description\":\"automation, consultancy, project management, web\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/ed.gs\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-GB\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\",\"name\":\"Ed\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-GB\",\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g\",\"caption\":\"Ed\"},\"url\":\"https:\/\/ed.gs\/author\/ed\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"MacOS sed \"Invalid Command Code\" - E","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/","og_locale":"en_GB","og_type":"article","og_title":"MacOS sed \"Invalid Command Code\" - E","og_description":"The version of sed that is shipped with OS X\/MacOS is different to that of most Linux distros in such that you have to issue an extra few characters to get it to do the same command. If you do the following you will result in a “invalid command code” error when trying to delete […]","og_url":"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/","og_site_name":"E","article_published_time":"2016-01-26T17:13:02+00:00","article_modified_time":"2020-11-04T11:01:04+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2016\/01\/gratisography-346H.jpg","type":"image\/jpeg"}],"author":"Ed","twitter_misc":{"Written by":"Ed","Estimated reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/","url":"https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/","name":"MacOS sed \"Invalid Command Code\" - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2016-01-26T17:13:02+00:00","dateModified":"2020-11-04T11:01:04+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2016\/01\/26\/macos-sed-invalid-command-code\/"]}]},{"@type":"WebSite","@id":"https:\/\/ed.gs\/#website","url":"https:\/\/ed.gs\/","name":"E","description":"automation, consultancy, project management, web","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ed.gs\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-GB"},{"@type":"Person","@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628","name":"Ed","image":{"@type":"ImageObject","inLanguage":"en-GB","@id":"https:\/\/ed.gs\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4fe1dfaed09e6bdceb557d3008f5cc47?s=96&d=mm&r=g","caption":"Ed"},"url":"https:\/\/ed.gs\/author\/ed\/"}]}},"_links":{"self":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3737"}],"collection":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/comments?post=3737"}],"version-history":[{"count":2,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3737\/revisions"}],"predecessor-version":[{"id":3921,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3737\/revisions\/3921"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3840"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=3737"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=3737"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=3737"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}