Find and replace nth instance of text string using python or bash -



Find and replace nth instance of text string using python or bash -

this question has reply here:

how replace nth occurrence of string using sed 1 reply

i have configuration file trying edit.

for illustration file says : listen = 1.1.1.1 , want listen = 2.2.2.2.

however word listen occurs in other places in file. want know how read in file , alter nth instance

assuming "listen = 1.1.1.1" appears on own line, alter 4th instance:

awk -v n=4 '/listen = / && ++m == n {$3 = "2.2.2.2"} 1' file > file.changed

python bash sed

Comments

Popular posts from this blog

ruby on rails - Devise Logout Error in RoR -

model view controller - MVC Rails Planning -

php - Working with pretty urls on apache and fastcgi after hhvm installation -