nummagumma2
asked on
More help with RegEx on DNS files
Further to: https://www.experts-exchange.com/questions/22074200/Need-help-with-Regular-Expression.html
Sample:
152.146.76.xx A 127.0.0.1
TXT ("B&P")
TXT ("B&P")
TXT ("B&P")
173.146.76.xx A 127.0.0.1
TXT ( "bud ziegelbauer 1/20/2005 7:12:23 PM" )
195.146.76.xx A 127.0.0.1
TXT ( "clifton gayle 8/21/2004 6:25:45 AM" )
221.146.76.xx A 127.0.0.1
TXT ( "winston redell 6/24/2005 11:42:28 AM" )
TXT ( "lemuel omdahl 6/24/2005 11:42:28 AM" )
239.146.76.xx A 127.0.0.1
TXT ("B&P")
4.146.76.xx A 127.0.0.1
TXT ( "bradley redmon 9/7/2004 4:54:06 AM" )
99.146.76.xx A 127.0.0.1
TXT ( "erin ficks 8/22/2004 11:34:31 PM" )
130.147.76.xx A 127.0.0.1
TXT ( "blaine thrune 6/21/2005 10:00:36 AM" )
TXT ( "jimmie kennard 6/21/2005 10:00:18 AM" )
TXT ( "german hurd 6/21/2005 10:00:11 AM" )
TXT ( "jc seymore 6/21/2005 10:00:10 AM" )
TXT ( "gerardo cheely 6/21/2005 10:00:09 AM" )
TXT ( "tommie bia 6/21/2005 9:59:58 AM" )
---
I want to remove all of the extra TXT lines, leaving only one (doesn't really matter which one).
Sample:
152.146.76.xx A 127.0.0.1
TXT ("B&P")
TXT ("B&P")
TXT ("B&P")
173.146.76.xx A 127.0.0.1
TXT ( "bud ziegelbauer 1/20/2005 7:12:23 PM" )
195.146.76.xx A 127.0.0.1
TXT ( "clifton gayle 8/21/2004 6:25:45 AM" )
221.146.76.xx A 127.0.0.1
TXT ( "winston redell 6/24/2005 11:42:28 AM" )
TXT ( "lemuel omdahl 6/24/2005 11:42:28 AM" )
239.146.76.xx A 127.0.0.1
TXT ("B&P")
4.146.76.xx A 127.0.0.1
TXT ( "bradley redmon 9/7/2004 4:54:06 AM" )
99.146.76.xx A 127.0.0.1
TXT ( "erin ficks 8/22/2004 11:34:31 PM" )
130.147.76.xx A 127.0.0.1
TXT ( "blaine thrune 6/21/2005 10:00:36 AM" )
TXT ( "jimmie kennard 6/21/2005 10:00:18 AM" )
TXT ( "german hurd 6/21/2005 10:00:11 AM" )
TXT ( "jc seymore 6/21/2005 10:00:10 AM" )
TXT ( "gerardo cheely 6/21/2005 10:00:09 AM" )
TXT ( "tommie bia 6/21/2005 9:59:58 AM" )
---
I want to remove all of the extra TXT lines, leaving only one (doesn't really matter which one).
ASKER
It's a good idea in concept, however this is a 200,000+ line file so that would be a lot of work to manually change the TXT value of those lines.
grep -v "^ *TXT" filename
maybe this would be better (handles tab chars as well)
grep -v "^\s*TXT" filename
grep -v "^\s*TXT" filename
ASKER
Honor - thanks too... This isn't a situation where I can use grep, since I'm using a specific text editor.
I ended up using
Search:
0.1\n^.+0.1\n
replace
0.1\n TXT ( "Multiple" )
which takes
130.147.76.xx A 127.0.0.1
TXT ( "blaine thrune 6/21/2005 10:00:36 AM" )
TXT ( "jimmie kennard 6/21/2005 10:00:18 AM" )
TXT ( "german hurd 6/21/2005 10:00:11 AM" )
TXT ( "jc seymore 6/21/2005 10:00:10 AM" )
TXT ( "gerardo cheely 6/21/2005 10:00:09 AM" )
TXT ( "tommie bia 6/21/2005 9:59:58 AM" )
and converts it to
130.147.76.xx A 127.0.0.1
TXT ( "multiple" )
I ended up using
Search:
0.1\n^.+0.1\n
replace
0.1\n TXT ( "Multiple" )
which takes
130.147.76.xx A 127.0.0.1
TXT ( "blaine thrune 6/21/2005 10:00:36 AM" )
TXT ( "jimmie kennard 6/21/2005 10:00:18 AM" )
TXT ( "german hurd 6/21/2005 10:00:11 AM" )
TXT ( "jc seymore 6/21/2005 10:00:10 AM" )
TXT ( "gerardo cheely 6/21/2005 10:00:09 AM" )
TXT ( "tommie bia 6/21/2005 9:59:58 AM" )
and converts it to
130.147.76.xx A 127.0.0.1
TXT ( "multiple" )
ah, sed...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
1. modify the TXT line that you want to keep by manually changing TXT to something else, say TXT_
2. run a global search and replace to delete all other TXT lines
3. replace TXT_ with TXT for the one line that you changed.
(i'm not completely sure of the syntax, but the idea to select only lines with "TXT followed by any number of blanks, followed by a "(" and chars to the end of the line
search for: TXT[ ]+\(.+
replace with: "" (nothing)