Topic: Search and Replace (1 of 11), Read 50 times
Conf: Search and Replace
From: Business Ink
Date: Tuesday, September 13, 2005 05:55 PM

Hello Folks,

I am a real beginner to vedit. I would like to create a short edit script/macro
then execute it from a command line against a file.

The edit functions I need to perform are

find and replace all occurances of "|000" with "" (replaces nulls nothing)
make all lines the same length ( pad function/macro line length of 162)
find and replace all occurances of "1DB800R" with "|012DB800R" ( |012) is the form feed or page eject character for printing

find and replace all occurances of "0" in column 1 with a " " (blank)
find and replace all occurances of "-" in column 1 with a " " (blank)

save my file.

Can someone help me out ?

//Edit Macro for my file

Begin_Of_File //open file

while (! At_EOF) { // while not At End_Of_File

Search("|000) //search for null
Replace("|000","",BEGIN+ALL+NOERR) //replace all nulls with nothing

Replace("1DB0080R","|012DB0080R",BEGIN+ALL+NOERR) //replace string

Search(|<"0") //Search for a "0" zero in column 1 of all lines
Replace("0"," ",BEGIN+ALL+NOERR) //replace all 0 ("0" zero) in column 1 with a space (" ")

Search(|<"-") //Search for a "-" dashes in column 1 of all lines
Replace("0"," ",BEGIN+ALL+NOERR) //replace all - ("-" dashes) in column 1 with a space (" ")

what else do I need ???? Please help

 


Topic: Search and Replace (2 of 11), Read 56 times
Conf: Search and Replace
From: Ian Binnie
Date: Tuesday, September 13, 2005 08:15 PM

What you have written looks OK.

There is no need for the While loop (each replace starts at the beginning.
There is no need for the searches, and if there should also have NOERR.

I have been writing Vedit macros for years.
I still develop each gradually, testing each step as I go.

I suggest that you first develop a macro & test it in Visual mode before trying to automate.


On 9/13/2005 5:55:34 PM, Business Ink wrote:
>Hello Folks,
>
>I am a real beginner to vedit.
>I would like to create a short
>edit script/macro
>then execute it from a command
>line against a file.
>
>The edit functions I need to
>perform are
>
>find and replace all
>occurances of "|000" with ""
>(replaces nulls nothing)
>make all lines the same length
>( pad function/macro line
>length of 162)
>find and replace all
>occurances of "1DB800R" with
>"|012DB800R" ( |012) is the
>form feed or page eject
>character for printing
>
>find and replace all
>occurances of "0" in column 1
>with a " " (blank)
>find and replace all
>occurances of "-" in column 1
>with a " " (blank)
>
>save my file.
>
>Can someone help me out ?
>
>//Edit Macro for my file
>
>Begin_Of_File
>//open file
>
>while (! At_EOF) {
>// while not At End_Of_File
>
>Search("|000) //search for
>null
>Replace("|000","",BEGIN+ALL+NO
>ERR) //replace all nulls
>with nothing
>
>Replace("1DB0080R","|012DB0080
>R",BEGIN+ALL+NOERR)
>//replace string
>
>Search(|<"0") //Search for
>a "0" zero in column 1 of all
>lines
>Replace("0","
>",BEGIN+ALL+NOERR) //replace
>all 0 ("0" zero) in column 1
>with a space (" ")
>
>Search(|<"-") //Search for
>a "-" dashes in column 1 of
>all lines
>Replace("0","
>",BEGIN+ALL+NOERR) //replace
>all - ("-" dashes) in column
>1 with a space (" ")
>
>what else do I need ????
>Please help

 


Topic: Search and Replace (4 of 11), Read 50 times
Conf: Search and Replace
From: Business Ink
Date: Tuesday, September 20, 2005 09:31 AM

Thanks for the reply. I have run the macro you suggested and it worked well for the most part. However, I end up with a message "End of Buffer 1 has been reached" and have to save/close the file manually. Any suggestions?

 


Topic: Re: Search and Replace (5 of 11), Read 45 times
Conf: Search and Replace
From: Christian Ziemski
Date: Wednesday, September 28, 2005 04:24 PM

On Tue, 20 Sep 2005 09:31:00 -0400, Business Ink wrote:

>Thanks for the reply. I have run the macro you suggested
>and it worked well for the most part. However, I end up with
>a message "End of Buffer 1 has been
>reached" and have to save/close the file manually.
>Any suggestions?

I assume that you tried Fritz' macro?

Then you should change the line with the Line command in the loop to:

repeat(all){
EOL()
ins_indent(162)
line(1, NOERR+ERRBREAK)
}

And add these two lines at the end of the macro:

File_Save()
Exit


Christian

 


Topic: Re: Search and Replace (6 of 11), Read 39 times
Conf: Search and Replace
From: Fritz Heberlein
Date: Thursday, November 03, 2005 06:38 AM

Sorry for my coming late to this discussion (i was in Cyprus - interesting, but hot & dusty):

>Then you should change the line with the
>Line command in the loop to:
>
>repeat(all){
> EOL()
> ins_indent(162)
> line(1, NOERR+ERRBREAK)
>}

I'm a bit confused by the combination of noerr and errbreak here: aren't that conflicting options?

Thanks,

Fritz

 


Topic: Re: Search and Replace (7 of 11), Read 38 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, November 03, 2005 07:40 AM

On 11/3/2005 6:38:23 AM, Fritz Heberlein wrote:
>
>>Then you should change the line with the Line command in the loop to:
>>
>>repeat(all){
>> EOL()
>> ins_indent(162)
>> line(1, NOERR+ERRBREAK)
>>}
>
>I'm a bit confused by the combination of noerr and
>errbreak here: aren't that conflicting options?

Those options are not conflicting.
But the NOERR may be redundant(=not necessary) here...

- NOERR prevents the macro from being interrupted by an error (e.g. EOF reached), it simply suppresses any error message.

- ERRBREAK does the same and additionally breaks out of any While, Do-While, For or Repeat loop


Christian

 


Topic: Re: Search and Replace (8 of 11), Read 37 times
Conf: Search and Replace
From: Ted Green
Date: Thursday, November 03, 2005 10:26 AM

At 06:38 AM 11/3/2005, you wrote:
>>Then you should change the line with the
>>Line command in the loop to:
>>
>>repeat(all){
>> EOL()
>> ins_indent(162)
>> line(1, NOERR+ERRBREAK)
>>}
>
>I'm a bit confused by the combination of noerr and errbreak here: aren't that conflicting options?

You are right. The correct command is Line(1,ERRBREAK).

Ted.

 


Topic: Re: Search and Replace (9 of 11), Read 38 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, November 03, 2005 11:28 AM

On 11/3/2005 10:26:03 AM, Ted Green wrote:
>>
>>> line(1, NOERR+ERRBREAK)
>>I'm a bit confused by the combination of noerr and errbreak here: aren't that conflicting options?
>
>You are right. The correct command is Line(1,ERRBREAK).

Now I am the one who is confused ;-)

Are those options really _conflicting_ or "only" somehow redundant in regard of suppressing the error (and so harmless if used together) like I wrote earlier?

Christian

 


Topic: Re: Search and Replace (10 of 11), Read 38 times
Conf: Search and Replace
From: Ted Green
Date: Thursday, November 03, 2005 12:32 PM

At 11:29 AM 11/3/2005, you wrote:
>>>> line(1, NOERR+ERRBREAK)
>>>I'm a bit confused by the combination of noerr and errbreak here: aren't that conflicting options?
>>
>>You are right. The correct command is Line(1,ERRBREAK).
>
>Now I am the one who is confused ;-)
>
>Are those options really _conflicting_ or "only" somehow redundant in regard of suppressing the error (and so harmless if used together) like I wrote earlier?

I think they are conflicting.
Evidently my code checks for ERRBREAK first; it is had checked for NOERR first, the macro would loop forever.

Ted.

 


Topic: Re: Search and Replace (11 of 11), Read 42 times
Conf: Search and Replace
From: Christian Ziemski
Date: Thursday, November 03, 2005 12:45 PM

On Thu, 03 Nov 2005 00:32:00 -0500, Ted Green wrote:

>>>>> line(1, NOERR+ERRBREAK)
>>
>>Are those options really _conflicting_ or "only" somehow redundant
>>in regard of suppressing the error (and so harmless if used
>>together) like I wrote earlier?
>
>I think they are conflicting.
>Evidently my code checks for ERRBREAK first; it is had checked for
>NOERR first, the macro would loop forever.

Hmmm, I often used that combination in the past (can't remember why)
without problems.

A short test shows:

BoF
repeat(ALL) {
Line(1, NOERR)
}

loops forever as expected.


BoF
repeat(ALL) {
Line(1, ERRBREAK)
}

stops at EndOfFile, as expected.


BoF
repeat(ALL) {
Line(1, NOERR+ERRBREAK)
}

stops at EndOfFile too, no difference visible to the one before.


It looks like as NOERR has no additional effect when used together
with ERRBREAK.
(It's really not an important issue, but now I'm curious...)


Christian

 


Topic: Search and Replace (3 of 11), Read 57 times
Conf: Search and Replace
From: Fritz Heberlein
Date: Wednesday, September 14, 2005 10:07 AM


1. You can do that:

>>

Search(|<"0") //Search for a "0" zero in column 1 of all lines
Replace("0"," ",BEGIN+ALL+NOERR) //replace all 0 ("0" zero) in column 1 with a space (" ")

Search(|<"-") //Search for a "-" dashes in column 1 of all lines
Replace("0"," ",BEGIN+ALL+NOERR) //replace all - ("-" dashes) in column 1 with a space (" ")

<<

with a single operation:


Replace("|{|<0,|<-}"," ",BEGIN+ALL+NOERR)

Search the help or the manual (p. 147) for "pattern matching codes"


2.

> make all lines the same length ( pad function/macro line length of 162)

repeat(all){
EOL()
ins_indent(162)
line()
}

ins_indent(162) does nothing if last character in line >= 162.

3. So, your macro would look like (untested!):

Replace("|000","",BEGIN+ALL+NOERR) //replace all nulls with nothing
Replace("1DB0080R","|012DB0080R",BEGIN+ALL+NOERR) //replace string
Replace("|{|<0,|<-}"," ",BEGIN+ALL+NOERR)
BOF()
repeat(all){
EOL()
ins_indent(162)
line()
}