|
Contro
|
 |
« on: August 12, 2012, 07:06:54 AM » |
|
Arranges in a txt file
I have a txt file with this :
first, second,third,fourth
and i would like to transform automatically in :
"first","second","third","fourth"
How can I find a script for doing this works and many other similars ?
Best Regards
|
|
|
|
|
Logged
|
|
|
|
|
Renegade
|
 |
« Reply #1 on: August 12, 2012, 07:18:25 AM » |
|
You can probably just open it in Excel, then save it as a CSV.
|
|
|
|
|
Logged
|
|
|
|
|
Contro
|
 |
« Reply #2 on: August 12, 2012, 09:27:40 AM » |
|
Nice idea indeed. But i am looking for a soft for doing modifications automatically in a text file. Do you know anyone ? Best Regards P.D. I begin just now to apply the great idea with excel. 
|
|
|
|
|
Logged
|
|
|
|
|
|
Contro
|
 |
« Reply #3 on: August 12, 2012, 09:38:44 AM » |
|
You can probably just open it in Excel, then save it as a CSV.
I don't know how to do it. I obtain first;second;third;fourth but without " 
|
|
|
|
|
Logged
|
|
|
|
|
iphigenie
|
 |
« Reply #4 on: August 12, 2012, 09:51:30 AM » |
|
You can probably just open it in Excel, then save it as a CSV.
I don't know how to do it. I obtain first;second;third;fourth but without "  yeah, Outlook will only add "" if there is a space or a comma/semi colon in the text I think. Extremely annoying as I too have needed to get proper quotes everywhere in the past. Trying to remember what I did
|
|
|
|
|
Logged
|
|
|
|
|
eleman
|
 |
« Reply #5 on: August 12, 2012, 10:21:32 AM » |
|
Open the file in notepad (or word, or any text editor you like). Get to search and replace function (ctrl-h usually). Replace all instances of , with "," Adjust spaces as you like.
|
|
|
|
|
Logged
|
|
|
|
|
Ath
|
 |
« Reply #6 on: August 12, 2012, 12:11:27 PM » |
|
You could try CSV Editor that has a lot of options specifically for csv files, also available in a Unicode-edition, and on top of that is free software 
|
|
|
|
|
Logged
|
|
|
|
|
jgpaiva
|
 |
« Reply #7 on: August 12, 2012, 12:27:40 PM » |
|
You could try CSV Editor that has a lot of options specifically for csv files, also available in a Unicode-edition, and on top of that is free software  That looks like an awesome recommendation 
|
|
|
|
|
Logged
|
|
|
|
|
barney
|
 |
« Reply #8 on: August 12, 2012, 01:16:35 PM » |
|
You could try CSV Editor that has a lot of options specifically for csv files, also available in a Unicode-edition, and on top of that is free software  That looks like an awesome recommendation  It is. Been using CSVed for years - nothing else I've tried touches it. It's not the automated result requested, but 'tis a beautiful alternative.
|
|
|
|
|
Logged
|
Make a good day ... barn
|
|
|
|
Contro
|
 |
« Reply #9 on: August 12, 2012, 05:08:56 PM » |
|
Open the file in notepad (or word, or any text editor you like). Get to search and replace function (ctrl-h usually). Replace all instances of , with "," Adjust spaces as you like.
and the commas at the beginning and the end ?
|
|
|
|
|
Logged
|
|
|
|
|
Contro
|
 |
« Reply #10 on: August 12, 2012, 05:09:42 PM » |
|
You could try CSV Editor that has a lot of options specifically for csv files, also available in a Unicode-edition, and on top of that is free software  Freeeetryinngggg Best Regards
|
|
|
|
|
Logged
|
|
|
|
|
Contro
|
 |
« Reply #11 on: August 12, 2012, 05:25:00 PM » |
|
Not bat, but I think CSV Editor is slow.  Any other idea ? Best Regards
|
|
|
|
|
Logged
|
|
|
|
|
eleman
|
 |
« Reply #12 on: August 13, 2012, 12:17:39 AM » |
|
Open the file in notepad (or word, or any text editor you like). Get to search and replace function (ctrl-h usually). Replace all instances of , with "," Adjust spaces as you like.
and the commas at the beginning and the end ? uh... there were none in your sample text 
|
|
|
|
|
Logged
|
|
|
|
|
4wd
|
 |
« Reply #13 on: August 13, 2012, 02:52:02 AM » |
|
and the commas at the beginning and the end ?
uh... there were none in your sample text  I think he meant the quotes inserted at the start/end. I'm pretty sure this could be done using regex but it's beyond my meagre knowledge. I managed to get the quotes inserted but I couldn't get rid of the extraneous spaces. eg. Using Online RegEx Editor:  Pressing RegexSplit will give: "first", "second","third","fourth"
|
|
|
|
|
Logged
|
Four wheel drive: Helping you get stuck faster, harder, further from help...........and it's no different on this forum 
|
|
|
|
AbteriX
|
 |
« Reply #14 on: August 13, 2012, 01:48:15 PM » |
|
Formatted for Generic Code with the GeSHI Syntax Highlighter [ copy or print] FROM: first field, second word, third column, fourth item TO: first field,second word,third column,fourth item Use RegEx Find: ,\s+(\w) Repl: ,\1
Formatted for Generic Code with the GeSHI Syntax Highlighter [ copy or print] FROM: first field,second word,third column,fourth item TO: "first field","second word","third column","fourth item" Use RegEx Find: ^(.+?),(.+?),(.+?),(.+)$ Repl: "\1","\2","\3","\4"
At least this works with EmEditor. For other regex engines the patter may slightly different. And often "$1" is used instead of "\" .
|
|
|
|
|
Logged
|
Greetings, Stefan.
|
|
|
|
sword
|
 |
« Reply #15 on: August 13, 2012, 03:32:03 PM » |
|
Re: Any other ideas...commas at beginning and end...CSV Editor is slow...many other similars
An idea, not a script: WordPerfect Find and Replace> 'spaces' with 'nothing. Find and Replace> , (comma) with ",". Insert between two quotes for beginning and end.
|
|
|
|
|
Logged
|
|
|
|
|
skwire
|
 |
« Reply #16 on: August 14, 2012, 10:05:37 AM » |
|
How can I find a script for doing this works and many other similars ? Contro, I'd like to offer some friendly advice, if I may. Spend some time learning a scripting language so tasks like these can be easily solved on your own (rather than waiting, potentially days, on forum replies). Here's an example in AutoHotkey. Save this code to a .AHK file and then drag and drop one of your text files onto the .AHK file you created. Formatted for Autohotkey with the GeSHI Syntax Highlighter [ copy or print] sFile = %1% ; Dropped filename path. { Loop, Parse , myData , `n , `r { ; Strip out extra whitespace. ; Replace all commas with quotes-comma-quotes. ; Rebuild file, adding quotes at the beginning and end ; of each line. myBlock .= """" . myLine . """`r`n" } ; Ask user to save file. { ; Delete original and save new file. Yes, we should save ; to a temp folder and such but that's out of scope for this ; simple script. { If ( ErrorLevel ) ; Basic sanity check to see if the file deleted. { MsgBox, 16, Error! , Could not overwrite file . Exiting ... } } ; Write file to disk. } }
|
|
|
|
« Last Edit: August 14, 2012, 10:17:00 AM by skwire »
|
Logged
|
|
|
|
|
Stoic Joker
|
 |
« Reply #17 on: August 14, 2012, 11:49:22 AM » |
|
Open the file in notepad (or word, or any text editor you like). Get to search and replace function (ctrl-h usually). Replace all instances of , with "," Adjust spaces as you like. I've had to do that a few times. Second part is to search for \r\n and replace it with "\r\n" to get the beginning and ending quotes. Granted that will depend on the editor...but it works for me in EmEditor.
|
|
|
|
|
Logged
|
|
|
|
|