vi Notes: global search and replace

When editing a large file with a common word that needs to be replaced throughout the entirety of the script try using the search and replace feature in vi

To perform a global search and replace, use the search and replace command in command mode:

  :%s/search_string/replacement_string/g

The % is a shortcut that tells vi to search all lines of the file for search_string and what to change it to as listed here in replacement_string. The global (g) flag at the end of the command tells vi to continue searching for other occurrences of search_string.

Thank me later, I just edited a 300 line configuration for NGINX Reverse Proxy to a large complex application environment. Seek and destroy!

Leave a Reply

RELATED POST

VirtualBox: Create vm from script

Edit a few variables prior to kicking off the script, for instance the host name in the variable VM='RHEL_6_5_5' to…

System Check before shift begins

Here is an oldie but goodie, right before my shift would begin here is a set of items to check…

Veritas Volume Manager: Growing a disk group and expand the filesystem

Validated by Mr Man! Lets start off on node2 [root@node02 ~]# vxdisk list DEVICE TYPE DISK GROUP STATUS sda auto:none…

Virtual Machine Manager: Error starting domain

Starting up the KVM error occurred Error starting domain: Requested operation is not valid: network 'default' is not active Locate…