{"id":317,"date":"2012-02-29T13:52:02","date_gmt":"2012-02-29T05:52:02","guid":{"rendered":"http:\/\/www.sysadmindayph.com\/blog\/?p=317"},"modified":"2012-06-16T22:16:46","modified_gmt":"2012-06-16T14:16:46","slug":"how-do-you-find-and-replace-expressions-in-vi-editor","status":"publish","type":"post","link":"https:\/\/www.sysadmindayph.com\/blog\/how-do-you-find-and-replace-expressions-in-vi-editor\/","title":{"rendered":"How Do you Find and Replace Expressions in VI Editor"},"content":{"rendered":"<p>One and for all, let&#8217;s do this again.. how do you do the find and replace function of the Vi editor? I keep on coming back to Google for the syntax but at least I know that there is an &#8216;s&#8217; in the beginning of the command and a &#8216;g&#8217; at the end (for Global search). \ud83d\ude42<\/p>\n<p>Anyway, a little background before i copy paste the information here. I first taught myself how to use Vi during my &#8216;first&#8217; job as a systems engineer in <a href=\"http:\/\/ph.tncsi.com\/\">NEC TNCSi<\/a>. Actually, my UNix foundation was all from NEC. Not that they train me how to be a unix admin, but I learned and taught myself how to do it. I read books that were lying around there and build samba servers, qmail and email servers and stuff until I got the ropes, the ins and outs of the UNix environment (Actually, I was using Linux &#8211; Redhat).<\/p>\n<h2>How Do You Find and Replace Text in Vi?<\/h2>\n<blockquote><p>To perform a global search and replace in vi, use the search and replace command in command mode:<\/p>\n<p>  <code>:%s\/search_string\/replacement_string\/g <\/code><\/p>\n<p>The % is a shortcut that tells vi to search all lines of the file for search_string and change it to replacement_string. The global ( g ) flag at the end of the command tells vi to continue searching for other occurrences of search_string . To confirm each replacement, add the confirm ( c ) flag after the global flag.<\/p>\n<\/blockquote>\n<p>For this latest usage, i need to change the shell for all the users who are using \/bin\/ksh to a safeword sid shell.<\/p>\n<p>remember to use the &#8216;slash&#8217; character if you are filtering actually backslash.. You do not want to misinterpret the &#8216;\/&#8217; character by vi.<\/p>\n<p>so, that&#8217;s<\/p>\n<p><code>:%s\/\\\/bin\\\/ksh\/\\\/bin\\\/sid\/g<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>One and for all, let&#8217;s do this again.. how do you do the find and replace function of the Vi editor? I keep on coming back to Google for the syntax but at least I &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16,10,5,3],"tags":[],"class_list":["post-317","post","type-post","status-publish","format-standard","hentry","category-commands","category-linux","category-solaris","category-unix"],"_links":{"self":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/317","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/comments?post=317"}],"version-history":[{"count":2,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions"}],"predecessor-version":[{"id":349,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/posts\/317\/revisions\/349"}],"wp:attachment":[{"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/media?parent=317"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/categories?post=317"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sysadmindayph.com\/blog\/wp-json\/wp\/v2\/tags?post=317"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}