Home > Unix > UNIX – Lesson 014 – vi editor – Simple Search and Search for text Patterns

UNIX – Lesson 014 – vi editor – Simple Search and Search for text Patterns


Global Search and Replace

:g/old_text/s//new_text/g            Unix style
:m,ns/old_pattern/new_text/g         Perl style

  • m and n              defines the lines the command should be executed on
  • s                         designates the substitute command
  • old_pattern         identifies the text pattern to search for
  • new_text            designates the replacement text string
  • g                         performs the command globally within the line

Example:

:g/one/s//two/g

:1,$s/one/two/g     It substitutes in each line (to the end of file $) the string “one” with the string “two”

Advertisements
Categories: Unix
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: