{"id":3797,"date":"2018-08-10T15:10:29","date_gmt":"2018-08-10T14:10:29","guid":{"rendered":"https:\/\/ed.gs\/?p=3797"},"modified":"2018-08-10T15:10:29","modified_gmt":"2018-08-10T14:10:29","slug":"matching-strings-in-variables-fish-shell","status":"publish","type":"post","link":"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/","title":{"rendered":"Matching Strings In Variables – Fish Shell"},"content":{"rendered":"

I’ve recently been completing some boring remediation work of changing some VM folder locations, which required me to change hundreds of tags, so I thought it would be worth seeing if Fish could help me out. <\/p>\n

I already knew that the file contents had the something similar to:<\/p>\n

default['vmfolder'] = "oldfolder"<\/pre>\n

I started out by creating an array of files that were owned by my team:<\/p>\n

for i in (grep -r "myteam" * | cut -d ':' -f1 | sort | uniq)\r\n     set servers (string join " " $servers $i)\r\n end<\/pre>\n

This gave me:<\/p>\n

ENV/server1.rb ENV/server2.rb ENV2/server1.rb ENV3/server1.rb ENV3/server2.rb<\/pre>\n

My main issue was that there were lots of different sites and they’d all need different tags for their new VM locations, but due to us having an array available of our files we could now loop through them and match the start of the environment to fix their locations.<\/p>\n

for i in $servers                                                                                                                                                                                                             \r\n     switch $i\r\n         case "*ENV*"\r\n             sed -i 's/oldfolder/ENV_TEAMNAME/' $i\r\n         case "*ENV2*"\r\n             sed -i 's/oldfolder/ENV2_TEAMNAME/' $i\r\n         case "*ENV3*"\r\n             sed -i 's/oldfolder/ENV3_TEAMNAME/' $i\r\n     end\r\n end<\/pre>\n

With that done I just had to push the contents back to our repo and I was done. Hope that helps someone else in the future.<\/p>\n","protected":false},"excerpt":{"rendered":"

I’ve recently been completing some boring remediation work of changing some VM folder locations, which required me to change hundreds of tags, so I thought it would be worth seeing if Fish could help me out. I already knew that the file contents had the something similar to: default['vmfolder'] = "oldfolder" I started out by […]<\/p>\n","protected":false},"author":2,"featured_media":3800,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ep_exclude_from_search":false},"categories":[198,196,197],"tags":[],"yoast_head":"\nMatching Strings In Variables - Fish Shell - 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\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/\" \/>\n<meta property=\"og:locale\" content=\"en_GB\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Matching Strings In Variables - Fish Shell - E\" \/>\n<meta property=\"og:description\" content=\"I’ve recently been completing some boring remediation work of changing some VM folder locations, which required me to change hundreds of tags, so I thought it would be worth seeing if Fish could help me out. I already knew that the file contents had the something similar to: default['vmfolder'] = "oldfolder" I started out by […]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/\" \/>\n<meta property=\"og:site_name\" content=\"E\" \/>\n<meta property=\"article:published_time\" content=\"2018-08-10T14:10:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/static.ed.gs\/wp-content\/uploads\/2018\/08\/gratisography-278H.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\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/\",\"url\":\"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/\",\"name\":\"Matching Strings In Variables - Fish Shell - E\",\"isPartOf\":{\"@id\":\"https:\/\/ed.gs\/#website\"},\"datePublished\":\"2018-08-10T14:10:29+00:00\",\"dateModified\":\"2018-08-10T14:10:29+00:00\",\"author\":{\"@id\":\"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628\"},\"inLanguage\":\"en-GB\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/\"]}]},{\"@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":"Matching Strings In Variables - Fish Shell - 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\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/","og_locale":"en_GB","og_type":"article","og_title":"Matching Strings In Variables - Fish Shell - E","og_description":"I’ve recently been completing some boring remediation work of changing some VM folder locations, which required me to change hundreds of tags, so I thought it would be worth seeing if Fish could help me out. I already knew that the file contents had the something similar to: default['vmfolder'] = "oldfolder" I started out by […]","og_url":"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/","og_site_name":"E","article_published_time":"2018-08-10T14:10:29+00:00","og_image":[{"width":2048,"height":1365,"url":"https:\/\/static.ed.gs\/wp-content\/uploads\/2018\/08\/gratisography-278H.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\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/","url":"https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/","name":"Matching Strings In Variables - Fish Shell - E","isPartOf":{"@id":"https:\/\/ed.gs\/#website"},"datePublished":"2018-08-10T14:10:29+00:00","dateModified":"2018-08-10T14:10:29+00:00","author":{"@id":"https:\/\/ed.gs\/#\/schema\/person\/d775615f2296ad0129fa3ea66346c628"},"inLanguage":"en-GB","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ed.gs\/2018\/08\/10\/matching-strings-in-variables-fish-shell\/"]}]},{"@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\/3797"}],"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=3797"}],"version-history":[{"count":0,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/posts\/3797\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media\/3800"}],"wp:attachment":[{"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/media?parent=3797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/categories?post=3797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ed.gs\/wp-json\/wp\/v2\/tags?post=3797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}