{"id":341,"date":"2022-11-09T15:35:37","date_gmt":"2022-11-09T15:35:37","guid":{"rendered":"https:\/\/www.jibsheet.net\/linux\/?p=341"},"modified":"2022-11-09T16:13:24","modified_gmt":"2022-11-09T16:13:24","slug":"use-sed-command-to-change-column-names-in-csv-files","status":"publish","type":"post","link":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/","title":{"rendered":"Use sed command to change column names in csv files"},"content":{"rendered":"<p>Problem:<\/p>\n<p>&#8211; You have several CSV file that have a title that needs to change.<\/p>\n<p>In my example I had a column name that was need to change from &#8220;Time(edt)&#8221; to just &#8220;Time&#8221;<\/p>\n<p>To run a test:<\/p>\n<p>note:\u00a0 no special backslash needed for &#8220;(&#8221; or &#8220;)&#8221;<\/p>\n<p>You can glob the files and it will do all of them.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sed 's\/Time(edt)\/Time\/g' KDCA_3_day_Y*.csv\r\n<\/pre>\n<p>Add the -i to do the deed in place<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sed -i 's\/Time(edt)\/Time\/g' KDCA_3_day_Y*.csv<\/pre>\n<p>For BSD &#8211; I got an error<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">[jon2allen@freebsd12_3 ~\/github\/weather_obs]$ sed -i 's\/Time(edt)\/Time\/g' KDCA_3_day_Y*.csv\r\nsed: 1: \"KDCA_3_day_Y2022_M09_D2 ...\": invalid command code K\r\n<\/pre>\n<p>The man page suggest that the -i flag can have a backup extension, and a zero byte would ignore it which doesn&#8217;t seem to be the case.<\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">sed -ibak 's\/Time(edt)\/Time\/g' KDCA_3_day_Y*.csv\r\n<\/pre>\n<p>It simply tacks on the extension to the end.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\"> bsduser\u00a0\u00a0bsduser\u00a0\u00a0\u00a0\u00a01265 Nov\u00a0\u00a09 11:05 KDCA_3_day_Y2022_M09_D27_H10.csv\r\n bsduser\u00a0\u00a0bsduser\u00a0\u00a0\u00a0\u00a01270 Sep 27 23:21 KDCA_3_day_Y2022_M09_D27_H10.csvbak\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem: &#8211; You have several CSV file that have a title that needs to change. In my example I had a column name that was need to change from &#8220;Time(edt)&#8221; to just &#8220;Time&#8221; To run a test: note:\u00a0 no special backslash needed for &#8220;(&#8221; or &#8220;)&#8221; You can glob the files and it will do all of them. sed &#8216;s\/Time(edt)\/Time\/g&#8217; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[22,28,5],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff<\/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:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"og:description\" content=\"Problem: &#8211; You have several CSV file that have a title that needs to change. In my example I had a column name that was need to change from &#8220;Time(edt)&#8221; to just &#8220;Time&#8221; To run a test: note:\u00a0 no special backslash needed for &#8220;(&#8221; or &#8220;)&#8221; You can glob the files and it will do all of them. sed &#039;s\/Time(edt)\/Time\/g&#039; [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\" \/>\n<meta property=\"og:site_name\" content=\"Jon Allen&#039;s Linux Stuff\" \/>\n<meta property=\"article:published_time\" content=\"2022-11-09T15:35:37+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-09T16:13:24+00:00\" \/>\n<meta name=\"author\" content=\"jonallen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"jonallen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. 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\":\"Article\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\"},\"author\":{\"name\":\"jonallen\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"headline\":\"Use sed command to change column names in csv files\",\"datePublished\":\"2022-11-09T15:35:37+00:00\",\"dateModified\":\"2022-11-09T16:13:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\"},\"wordCount\":123,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"articleSection\":[\"bash\",\"BSD\",\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\",\"name\":\"Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff\",\"isPartOf\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\"},\"datePublished\":\"2022-11-09T15:35:37+00:00\",\"dateModified\":\"2022-11-09T16:13:24+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.jibsheet.net\/linux\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Use sed command to change column names in csv files\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#website\",\"url\":\"https:\/\/www.jibsheet.net\/linux\/\",\"name\":\"Jon Allen's Linux Stuff\",\"description\":\"Howto&#039;s, Observations, and stuff\",\"publisher\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993\",\"name\":\"jonallen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g\",\"caption\":\"jonallen\"},\"logo\":{\"@id\":\"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/\"},\"sameAs\":[\"https:\/\/www.jibsheet.net\/linux\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff","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:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/","og_locale":"en_US","og_type":"article","og_title":"Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff","og_description":"Problem: &#8211; You have several CSV file that have a title that needs to change. In my example I had a column name that was need to change from &#8220;Time(edt)&#8221; to just &#8220;Time&#8221; To run a test: note:\u00a0 no special backslash needed for &#8220;(&#8221; or &#8220;)&#8221; You can glob the files and it will do all of them. sed 's\/Time(edt)\/Time\/g' [&hellip;]","og_url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/","og_site_name":"Jon Allen&#039;s Linux Stuff","article_published_time":"2022-11-09T15:35:37+00:00","article_modified_time":"2022-11-09T16:13:24+00:00","author":"jonallen","twitter_card":"summary_large_image","twitter_misc":{"Written by":"jonallen","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#article","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/"},"author":{"name":"jonallen","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"headline":"Use sed command to change column names in csv files","datePublished":"2022-11-09T15:35:37+00:00","dateModified":"2022-11-09T16:13:24+00:00","mainEntityOfPage":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/"},"wordCount":123,"commentCount":0,"publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"articleSection":["bash","BSD","Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/","url":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/","name":"Use sed command to change column names in csv files - Jon Allen&#039;s Linux Stuff","isPartOf":{"@id":"https:\/\/www.jibsheet.net\/linux\/#website"},"datePublished":"2022-11-09T15:35:37+00:00","dateModified":"2022-11-09T16:13:24+00:00","breadcrumb":{"@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.jibsheet.net\/linux\/index.php\/2022\/11\/09\/use-sed-command-to-change-column-names-in-csv-files\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.jibsheet.net\/linux\/"},{"@type":"ListItem","position":2,"name":"Use sed command to change column names in csv files"}]},{"@type":"WebSite","@id":"https:\/\/www.jibsheet.net\/linux\/#website","url":"https:\/\/www.jibsheet.net\/linux\/","name":"Jon Allen's Linux Stuff","description":"Howto&#039;s, Observations, and stuff","publisher":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.jibsheet.net\/linux\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/295a80d0b2aa929b648c4fdddee83993","name":"jonallen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/7d7c061ce9db8f5e4710555585475882?s=96&d=mm&r=g","caption":"jonallen"},"logo":{"@id":"https:\/\/www.jibsheet.net\/linux\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/www.jibsheet.net\/linux"]}]}},"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/341"}],"collection":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/comments?post=341"}],"version-history":[{"count":3,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions"}],"predecessor-version":[{"id":344,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/posts\/341\/revisions\/344"}],"wp:attachment":[{"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/media?parent=341"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/categories?post=341"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jibsheet.net\/linux\/index.php\/wp-json\/wp\/v2\/tags?post=341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}