Monday, 26 January 2015

Use vi to replace some pattern, but only for specific lines

Sometimes is very handful to use the Unix/Linux utility "vi" to replace a specific pattern, but there is a special syntax if we only want to do it for a specific range of rows, see exmaple below:

Use find and replace on line ranges (match by line numbers)

You can also make changes on range of lines i.e. replace first occurrence of foo with bar on lines 5 through 20 only, enter:
:5,20s/foo/bar/

No comments:

Post a Comment