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 replyi 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
Post a Comment