Hello,
I'm looking to add double quotes to all fields in a comma delimited file that do not already have double quotes.
i.e.
Here is a sample record with 3 fields.
Thanks for the reply. I guess I was assuming that you knew "Text" fields can have commas in the middle of the field.
i.e. "123 Fake St. Fakville,WA"
I appreciate the feedback, but that will not work in my case. That is why I'd like to set-up a Regular Expression that will validate if the field has double quotes around it already. If the field does not, add double quotes. This is not an emergency, so don't go writing something that isn't already coded.
Thanks for the Expression. There is obviously something that I'm not telling you because the last Find/Replace didn't find anything. I'm going to look at the help section for regular expressions and decode your awsome regular expression syntax. This is definately a new subject that I'm really interested in so no need to debug my problem. Thanks a million for the code.
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.
Best regards from an UC/UE/UES for Windows user from Austria