Okay, the following macro hopefully does the job. I hope, there is always only 1 tab between the columns and so that part of the file is like a CSV file with the tab as delimiter.
Make sure all open files are saved before running the macro. The macro must temporarily modify every file, but does not really change the contents. All files which remain open are indicated as modified although the contents of the still open files are not changed by the macro (except for missing line termination at end of the file).
The macro property
Continue if a Find with Replace not found must be checked for this macro.
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
Top
"ThIs Is ThE FiRsT FiLe!"
NextWindow
Loop
Bottom
IfColNum 1
Else
"
"
EndIf
Top
Find MatchCase "HEADER1"
IfFound
Key Ctrl+LEFT ARROW
StartSelect
Key HOME
Copy
EndSelect
Top
Paste
"
"
Key UP ARROW
SelectLine
Find RegExp "[~^t^p]+^t"
Replace All SelectText "*^^^^t"
EndSelect
Top
"%"
Key END
"[0-9].[0-9][0-9][0-9][^t^r^n]"
StartSelect
Key HOME
Cut
EndSelect
DeleteLine
Find RegExp "^c"
IfNotFound
Top
EndIf
Else
Top
EndIf
IfSel
Top
Find MatchCase "ThIs Is ThE FiRsT FiLe!"
Replace ""
IfFound
Find RegExp "^c"
ExitLoop
EndIf
Find RegExp "^c"
NextWindow
Else
Find MatchCase "ThIs Is ThE FiRsT FiLe!"
Replace ""
IfFound
CloseFile NoSave
ExitLoop
Else
CloseFile NoSave
EndIf
EndIf
EndLoop
ClearClipboard
Clipboard 0
Here is the macro again in UEM format with comments - see
Macro examples and reference for beginners and experts how to setup UltraEdit to best view a macro code in this format. I have used 4 spaces instead of every tab (used command Tabs To Spaces) to get a correct HTML output here.
Code: Select all
InsertMode
ColumnModeOff
HexOff
UnixReOff
Clipboard 9
// Mark the first file with a special string to know when to exit the loop.
Top
"ThIs Is ThE FiRsT FiLe!"
/*! The first file must be evaluated as last file because it propably does not
not contain the string of interest. The macro then could not close it to
avoid an endless loop, although it should be close. So better evaluate
the first file as last file. !*/
NextWindow
Loop
/*! Insert a line termination at end of the file if last line is not already terminated.
This is necessary when the column HEADER1 is the last column and so after ?.??? the
line termination follows. !*/
Bottom
IfColNum 1
Else
"
"
EndIf
Top
/*! Back at top of the file search for the header. If not found, ignore this file and
later close it, because it surely does not contain ?.??? in the requested column. !*/
Find MatchCase "HEADER1"
IfFound
/*! Header found! Copy everything from start of the current line
to beginning of HEADER1 into a new line at top of the file. !*/
Key Ctrl+LEFT ARROW
StartSelect
Key HOME
Copy
EndSelect
Top
Paste
"
"
Key UP ARROW
SelectLine
/*! Convert now this part of the header line into an UltraEdit style regular expression
with the required part to find ?.??? at end of the column or line, if the HEADER1
column is the last column. A header line like
Description ABC CBA HEADER1 ...
will be converted into
%*^t*^t*^t[0-9].[0-9][0-9][0-9][^t^r^n]
!*/
Find RegExp "[~^t^p]+^t"
Replace All SelectText "*^^^^t"
EndSelect
Top
"%"
Key END
"[0-9].[0-9][0-9][0-9][^t^r^n]"
// Copy this line into the user clipboard 9 and delete the line.
StartSelect
Key HOME
Cut
EndSelect
DeleteLine
// Search for the regular expression in the clipboard. This works only with UE style.
Find RegExp "^c"
// This useless looking code is necessary for the second Find/Replace in the Else branch.
IfNotFound
Top
EndIf
// This useless looking code is necessary for the second Find/Replace in the Else branch.
Else
Top
EndIf
IfSel
/*! The regular expression has found ?.??? in the correct column. So don't close
this file, but exit the loop when this file is the first/last file to evaluate.
But before always position the cursor to the string of interest. !*/
Top
Find MatchCase "ThIs Is ThE FiRsT FiLe!"
Replace ""
IfFound
Find RegExp "^c"
ExitLoop
EndIf
Find RegExp "^c"
NextWindow
Else
/*! No HEADER1 or no ?.??? in the column of HEADER1 - close the file. But first check
if this file is the first/last file to evaluate and exit the loop if this is true. !*/
Find MatchCase "ThIs Is ThE FiRsT FiLe!"
Replace ""
IfFound
CloseFile NoSave
ExitLoop
Else
CloseFile NoSave
EndIf
EndIf
EndLoop
ClearClipboard
Clipboard 0