{"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>\nI 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>\nThis gave me:<\/p>\n
ENV/server1.rb ENV/server2.rb ENV2/server1.rb ENV3/server1.rb ENV3/server2.rb<\/pre>\nMy 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>\nWith 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":"\n
Matching Strings In Variables - Fish Shell - E<\/title>\n\n\n\n\n\n\n\n\n\n\n\t\n\t\n\t\n\n\n\t\n\t\n\t\n