VIM edit only between specific line numbers

To edit content between specific line numbers use following expression in vim editor

:startLineNumber,endLineNumbers/search/replace/g

In above expression add s after end line number.

Example:

Add # character at a starting of the line from line number 3 10 use following expression in vim:

:3,10s/^/#/g

To replace all foo’s with bar’s from line 3 to 10 use following expressin:

:3,10s/foo/bar/g

We can achieve same functionalities with sed expression also with following expressions:

$ sed -i "3,10s/^/#/g" inputFileName
$ sed -i "3,10s/foo/bar/g" inputFileName

-Sany

Advertisements
By Sandeep Posted in sed, vim

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