Find the phrase and delete the complete line using reg-ex
Posted: Mon Sep 06, 2010 3:28 pm
Hello:
I have several text script files where password is clearly mentioned. Below is just as an example. I am looking for a regex where I can find the phrase “password� and replace the matching line with some string ex. Password removed. Contact admin at ext 10101 or just wanted to delete line completely.
Thanks in advanced.
Sample original Text
snmp-server community public
snmp-server password public
snmp-server enable traps isdn
snmp-server host 172.16.1.27 version 2c public
snmp-server host 172.16.1.111 version 1 public
snmp-server host 172.16.1.33 public
Sample output Text
snmp-server community public
Password removed.!
Contact admin at ext 10101
snmp-server enable traps isdn
snmp-server host 172.16.1.27 version 2c public
snmp-server host 172.16.1.111 version 1 public
snmp-server host 172.16.1.33 public
I have several text script files where password is clearly mentioned. Below is just as an example. I am looking for a regex where I can find the phrase “password� and replace the matching line with some string ex. Password removed. Contact admin at ext 10101 or just wanted to delete line completely.
Thanks in advanced.
Sample original Text
snmp-server community public
snmp-server password public
snmp-server enable traps isdn
snmp-server host 172.16.1.27 version 2c public
snmp-server host 172.16.1.111 version 1 public
snmp-server host 172.16.1.33 public
Sample output Text
snmp-server community public
Password removed.!
Contact admin at ext 10101
snmp-server enable traps isdn
snmp-server host 172.16.1.27 version 2c public
snmp-server host 172.16.1.111 version 1 public
snmp-server host 172.16.1.33 public