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
Find the phrase and delete the complete line using reg-ex
Moderators: AmigoJack, bbadmin, helios, MudGuard
-
g114112118s
- Posts: 5
- Joined: Mon Sep 06, 2010 3:25 pm
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
-
g114112118s
- Posts: 5
- Joined: Mon Sep 06, 2010 3:25 pm
Re:Find the phrase and delete the complete line using reg-ex
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
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
-
ben_josephs
- Posts: 2464
- Joined: Sun Mar 02, 2003 9:22 pm
-
g114112118s
- Posts: 5
- Joined: Mon Sep 06, 2010 3:25 pm
Re:Find the phrase and delete the complete line using reg-ex
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
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
-
g114112118s
- Posts: 5
- Joined: Mon Sep 06, 2010 3:25 pm
Re:Find the phrase and delete the complete line using reg-ex
Hi, ben_josephs,
Thanks for the help & support
For the my least query; $0 works for me. and i have no further questions.
Thanks,
Ankur
Thanks for the help & support
Thanks,
Ankur
-
g114112118s
- Posts: 5
- Joined: Mon Sep 06, 2010 3:25 pm
Re:Find the phrase and delete the complete line using reg-ex
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.
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.
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.