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

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -