by Mofi » Mon Jan 23, 2006 7:50 am
I have detected, that my 3 replaces are not enough and you will get a bad file, if there are ',' inside a cell or a cell is empty (= ,, in the file).
Here is a macro, which should do the job better. Don't forget to enable the macro property Continue if a Find with Replace not found.
InsertMode
ColumnModeOff
HexOff
UnixReOff
TrimTrailingSpaces
Bottom
IfColNum 1
Else
"
"
EndIf
Top
Loop
Find RegExp ""*""
IfFound
Find ","
Replace All SelectText ";MOFI;"
EndSelect
Else
ExitLoop
EndIf
EndLoop
Top
Find RegExp "%^([~"^p]*^),"
Replace All ""^1","
Loop
Find RegExp ",^([~",^p]*^),"
Replace All ","^1","
IfNotFound
ExitLoop
EndIf
EndLoop
Find RegExp ",^([~",^p]*^)^p"
Replace All ","^1"^p"
Find MatchCase ";MOFI;"
Replace All ","
Top
UnixReOn
Remove the last red command, if you use regular expression in UltraEdit style by default instead of Unix style.
For UltraEdit v11.10c and lower see Advanced - Configuration - Find - Unix style Regular Expressions.
For UltraEdit v11.20 and higher see Advanced - Configuration - Searching - Unix style Regular Expressions.
Macro commands UnixReOn/UnixReOff modifies this setting.
How this macro works:
1) Make sure that last line of the file is terminated with a line break.
2) Search in a loop for all "..." cells and replace all ',' inside such cells by ";MOFI;".
3) Add "" to all cells of first column which do not already have it. "%^([~"^p]*^)," means find a string with 1 or more characters til ',' at start of the line and where the first character is not a " or a DOS line break (empty line).
4) Add "" to all cells, which are not empty (,,) and do not already have "" in column 2 til last column-1.
5) Add "" to all cells of last column (no , at the end, but a line break) which do not already have it.
6) Convert the ";MOFI;" strings back to , as it should be.
The macro is designed for working on a DOS terminated file. If you have a Unix file opened in Unix mode, you have to use ^n instead of ^p.