Topic: Remove lines that do not contain a string (1 of 7), Read 20 times
Conf: Search and Replace
From: Nicholas Then
Date: Thursday, January 29, 2009 09:10 PM

I am looking for a way to remove any line that does not contain a date in the following format 01/01/1900. Does anyone know of a simple macro that can do this? Is is also possible in the macro not to show any error messages?

 


Topic: Remove lines that do not contain a string (2 of 7), Read 19 times
Conf: Search and Replace
From: Ian Binnie
Date: Thursday, January 29, 2009 10:46 PM

On 1/29/2009 9:10:01 PM, Nicholas Then wrote:
>I am looking for a way to
>remove any line that does not
>contain a date in the
>following format 01/01/1900.
>Does anyone know of a simple
>macro that can do this? Is is
>also possible in the macro not
>to show any error messages?

I have written many macros to convert/find dates, but none to do what you want.
The most practical use regular expressions.

The following is an example:-

// This macro changes English date to International format
// Ian Binnie 2007-09-05

Replace("([0-1]?[0-9])[-/]([0-3]?[0-9])[-/]([12][90][0-9][0-9])","\3-\1-\2",MAX|REGEXP|NOERR)


To find a date use the following:-
Search("([0-1]?[0-9])[-/]([0-3]?[0-9])[-/]([12][90][0-9][0-9])",MAX|REGEXP|NOERR)

(This would need to be modified if you use those funny US dates.)

You could include in a loop, with something like the following to copy the entire line to a register.
Reg_Copy_Block(30,BOL_Pos, EOL_Pos,APPEND)

 


Topic: Remove lines that do not contain a string (5 of 7), Read 16 times
Conf: Search and Replace
From: Nicholas Then
Date: Friday, January 30, 2009 05:33 PM

Is there an easy way to do the loop? I just installed vEdit a few weeks ago and am still getting the hang of it. It makes sense to copy lines to a register. After all are copied, it is pretty easy to clear the contents of the file and paste the register in its place?

 


Topic: Remove lines that do not contain a string (6 of 7), Read 16 times
Conf: Search and Replace
From: Ian Binnie
Date: Friday, January 30, 2009 08:27 PM

On 1/30/2009 5:33:37 PM, Nicholas Then wrote:
>Is there an easy way to do the
>loop? I just installed vEdit
>a few weeks ago and am still
>getting the hang of it. It
>makes sense to copy lines to a
>register. After all are
>copied, it is pretty easy to
>clear the contents of the file
>and paste the register in its
>place?

The following is an example of a loop:-

Begin_Of_File
Reg_Empty(30)

while(!At_EOF)
{
Search("([0-1]?[0-9])[-/]([0-3]?[0-9])[-/]([12][90][0-9][0-9])",MAX|REGEXP|ADVANCE|ERRBREAK)
Reg_Copy_Block(30,BOL_Pos, EOL_Pos+2,APPEND)
}


This does work, but I would not be entirely happy with it.
The original did not incde the CR/LF - hence the +2 which is a kludge.

It would also have problems with large files.
In practice I would put output into a file, but this gets a bit more complex.

You would be better to use the approach suggested by Ted:-

{MISC, More Macros, Line Filter}

Use the following search string, and regular expressions
([0-1]?[0-9])[-/]([0-3]?[0-9])[-/]([12][90][0-9][0-9])


For US format dates you should swap the first 2 groups
([0-1]?[0-9])
([0-3]?[0-9])

 


Topic: Re: Remove lines that do not contain a string (3 of 7), Read 17 times
Conf: Search and Replace
From: Ted Green
Date: Thursday, January 29, 2009 11:29 PM

At 09:34 PM 1/29/2009, you wrote:
>From: "Nicholas Then"
>
>I am looking for a way to remove any line that does not contain a date in the following format 01/01/1900. Does anyone know of a simple macro that can do this?

The function {MISC, More Macros, Line Filter} should be able to do this.
Select "-without the search string"
and enter for the search string:

|d|d/|d|d?|d|d|d|d

I haven't actually tried this, but the search string should be pretty close.
How well it works may depend upon the exact data. (Your mileage may vary.)

Ted.

 


Topic: Re: Remove lines that do not contain a string (4 of 7), Read 16 times
Conf: Search and Replace
From: Ian Binnie
Date: Friday, January 30, 2009 06:57 AM

On 1/29/2009 11:29:54 PM, Ted Green wrote:
>At 09:34 PM 1/29/2009, you
>wrote:
>>From: "Nicholas Then"
>>
>>I am looking for a way to remove any line that does not contain a date in the following format 01/01/1900. Does anyone know of a simple macro that can do this?
>
>The function {MISC, More
>Macros, Line Filter} should be
>able to do this.
>Select "-without the search
>string"
>and enter for the search
>string:
>
> |d|d/|d|d?|d|d|d|d
>
>I haven't actually tried this,
>but the search string should
>be pretty close.
>How well it works may depend
>upon the exact data. (Your
>mileage may vary.)

I didn't know of this macro.
It would work better with the regular expression option, using the filter I posted above.

 


Topic: Re: Remove lines that do not contain a string (7 of 7), Read 12 times
Conf: Search and Replace
From: Pauli Lindgren
Date: Monday, February 02, 2009 12:23 PM

Or you could use the following macro:

While(!At_EOF) {
if (Search_Block("|d|d/|d|d/|d|d|d|d", CP, EOL_pos, NOERR) == 0) {
Del_Line(1)
} else {
Line(1, ERRBREAK)
}
}


Or, with regular expression that gives slightly more specific match:
While(!At_EOF) {
if (Search_Block("[0-1]?[0-9]/[0-3]?[0-9]/[12][90][0-9][0-9]", CP, EOL_pos, REGEXP+WORD+NOERR) == 0) {
Del_Line(1)
} else {
Line(1, ERRBREAK)
}
}

--
Pauli