Solved

More help with RegEx on DNS files

Posted on 2006-11-28
8
269 Views
Last Modified: 2010-04-16
Further to: http://www.experts-exchange.com/Programming/Q_22074200.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).


0
Comment
Question by:nummagumma2
8 Comments
 
LVL 4

Expert Comment

by:chhokra_expert
ID: 18031354
how about you simplify the problem a little bit...
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)

0
 
LVL 1

Author Comment

by:nummagumma2
ID: 18032987
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.
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 18033308
grep -v "^  *TXT" filename
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 41

Expert Comment

by:HonorGod
ID: 18033312
maybe this would be better (handles tab chars as well)

grep -v "^\s*TXT" filename
0
 
LVL 1

Author Comment

by:nummagumma2
ID: 18050588
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" )
0
 
LVL 41

Expert Comment

by:HonorGod
ID: 18050905
ah, sed...
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 18320647
PAQed with points refunded (250)

Computer101
EE Admin
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
count7 challenge 12 70
wordmultiple challenge 12 92
Coldfusion RegEx 8 49
Powershell String Parsing with Regular Expression 19 12
Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now