Page 1 of 1

Find the phrase and delete the complete line using reg-ex

Posted: Mon Sep 06, 2010 3:28 pm
by g114112118s
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

Posted: Mon Sep 06, 2010 4:23 pm
by ben_josephs
Find what: .*password.*
Replace with: Password removed.!

[X] Regular expression

Replace All

Re:Find the phrase and delete the complete line using reg-ex

Posted: Mon Sep 06, 2010 5:11 pm
by g114112118s
Hi, ben_josephs, :-)

Thanks a lot; it's truly mind blowing , I would apprentice if you can give me some little more direction.

in my example; if their line has phrased "snmp" & "isdn"; I need to put some instruction in next line. However, I also want intact matched phrase line .

Again, 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 Text output

snmp-server community public
Password removed.!
Contact admin at ext 10101
snmp-server enable traps isdn
#ISDN circuit number: TBA
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

Posted: Mon Sep 06, 2010 7:11 pm
by ben_josephs
Find what: .*snmp.*isdn.*
Replace with: Contact admin at ext 10101\n\0\n#ISDN circuit number: TBA

[X] Regular expression

Replace All

Re:Find the phrase and delete the complete line using reg-ex

Posted: Mon Sep 06, 2010 7:45 pm
by g114112118s
WoW; Thanks...This will helps me a lot.....BTW; i got a small issue here...I tried some combination but I can't be able to figure it out...i got following output. However , I am excepting "snmp-server enable traps isdn" instead of "0". i am sorry for keep you bothering.

snmp-server community public
snmp-server password public
Contact admin at ext 10101
0
#ISDN circuit number: TBA
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

Re:Find the phrase and delete the complete line using reg-ex

Posted: Mon Sep 06, 2010 8:18 pm
by g114112118s
Hi, ben_josephs,

Thanks for the help & support :D For the my least query; $0 works for me. and i have no further questions.


Thanks,
Ankur

Posted: Mon Sep 06, 2010 9:05 pm
by ben_josephs
Then you are not using TextPad.

Re:Find the phrase and delete the complete line using reg-ex

Posted: Mon Sep 06, 2010 9:50 pm
by g114112118s
That's true; I am in Tokyo and it's over mid-night here. So I don't want o walk-up i7 to disturb other. :lol: I used to TextPad a lot 5 years ago. But now I am far from software development. I am occasionally using TextPad for the macro or bulks changes. i need integrated telnet/ssh with TextPad. But it's not a realistic demand. i gave a shot to WildEdit but i may need some more time to familiar with it.

If possible i need some direction for two cases.

CASE-I: How to delete all the lines with does not contain a particular phrase.

CASE-II: I need some help to get desired output. seems i am missing very small element here.

Input Text
snmp-server community public
snmp-server password public
snmp-server enable traps isdn
#ISDN circuit number: TBA
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

RegEx
Find what: ^.*circuit.*$
Replace with: 1.\n2.\n3.\n4.\n$0\n5.\n\6.\n7.

Output based on Regex
snmp-server community public
snmp-server password public
snmp-server enable traps isdn
1.
2.
3.
4.
#ISDN circuit number: TBA
5.
6.
7.
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

Desired output.
Find what: ^.*circuit.*$
Replace with: -need help


1.
snmp-server community public
2.
snmp-server password public
3.
snmp-server enable traps isdn
4.
#ISDN circuit number: TBA
5.
snmp-server host 172.16.1.27 version 2c public
6.
snmp-server host 172.16.1.111 version 1 public
7.
snmp-server host 172.16.1.33 public

Thanks, Again.