Welcome Guest.   Make a donation to an author on the site September 17, 2014, 04:39:14 PM  *

Please login or register.
Or did you miss your validation email?


Login with username and password (forgot your password?)
Why not become a lifetime supporting member of the site with a one-time donation of any amount? Your donation entitles you to a ton of additional benefits, including access to exclusive discounts and downloads, the ability to enter monthly free software drawings, and a single non-expiring license key for all of our programs.


You must sign up here before you can post and access some areas of the site. Registration is totally free and confidential.
 
The N.A.N.Y. Challenge 2011! Download 30+ custom programs!
   
   Forum Home   Thread Marks Chat! Downloads Search Login Register  
Pages: [1]   Go Down
  Reply  |  New Topic  |  Print  
Author Topic: Arranges in a txt file  (Read 2713 times)
Contro
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« 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
Charter Member
***
Posts: 11,362



Tell me something you don't know...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker
Contro
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« 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.

 Kiss
Logged
Contro
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« 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 "
 embarassed
Logged
iphigenie
Supporting Member
**
Posts: 1,166


curiosity FTW!

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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 "
 embarassed

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
Supporting Member
**
Posts: 269

see users location on a map View Profile Give some DonationCredits to this forum member
« 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
Supporting Member
**
Posts: 2,212



see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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 smiley
Logged

jgpaiva
Global Moderator
*****
Posts: 4,710



Artificial Idiocy

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« 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 smiley
That looks like an awesome recommendation  Thmbsup
Logged

barney
Charter Member
***
Posts: 1,244


see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« 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 smiley
That looks like an awesome recommendation  Thmbsup

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
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« 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
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« 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 smiley

Freeeetryinngggg

Best Regards
Logged
Contro
Participant
*
Posts: 2,120

View Profile Give some DonationCredits to this forum member
« Reply #11 on: August 12, 2012, 05:25:00 PM »

Not bat, but I think CSV Editor is slow.

 embarassed

Any other idea ?

Best Regards
Logged
eleman
Supporting Member
**
Posts: 269

see users location on a map View Profile Give some DonationCredits to this forum member
« 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 smiley
Logged
4wd
Supporting Member
**
Posts: 3,332



see users location on a map View Profile Read user's biography. Give some DonationCredits to this forum member
« 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 smiley

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

I do not need to control my anger ... people just need to stop pissing me off!
AbteriX
Charter Honorary Member
***
Posts: 1,050


Member #520

see users location on a map View Profile WWW Read user's biography. Give some DonationCredits to this forum member
« Reply #14 on: August 13, 2012, 01:48:15 PM »

Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
  1. FROM:
  2. first field,    second word, third column,  fourth item
  3. TO:
  4. first field,second word,third column,fourth item
  5.  
  6. Use RegEx
  7. Find: ,\s+(\w)
  8. Repl: ,\1


Formatted for Generic Code with the GeSHI Syntax Highlighter [copy or print]
  1. FROM:
  2. first field,second word,third column,fourth item
  3. TO:
  4. "first field","second word","third column","fourth item"
  5.  
  6. Use RegEx
  7. Find: ^(.+?),(.+?),(.+?),(.+)$
  8. 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
Charter Member
***
Posts: 182


View Profile Give some DonationCredits to this forum member
« 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
Charter Member
***
Posts: 4,072



Another Coding Snack request? Om nom nom...

see users location on a map View Profile WWW Give some DonationCredits to this forum member
« 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]
  1. sFile = %1% ; Dropped filename path.
  2. If ( sFile )
  3. {
  4.    FileRead, myData, % sFile
  5.    Loop, Parse, myData, `n, `r
  6.    {
  7.        ; Strip out extra whitespace.
  8.        myLine := RegExReplace( A_LoopField, ",\s+(\w)", ",$1" )
  9.        ; Replace all commas with quotes-comma-quotes.
  10.        StringReplace, myLine, myLine, `,, "`,", All
  11.        ; Rebuild file, adding quotes at the beginning and end
  12.        ; of each line.
  13.        myBlock .= """" . myLine . """`r`n"
  14.    }
  15.    ; Ask user to save file.
  16.    FileSelectFile, mySelectedFile, S16, % sFile, Save as...,
  17.    If ! ( ErrorLevel ) ; User did not cancel, proceed.
  18.    {
  19.        ; Delete original and save new file.  Yes, we should save
  20.        ; to a temp folder and such but that's out of scope for this
  21.        ; simple script.
  22.        If FileExist( mySelectedFile )
  23.        {
  24.            FileDelete, % mySelectedFile
  25.            If ( ErrorLevel ) ; Basic sanity check to see if the file deleted.
  26.            {
  27.                MsgBox, 16, Error!, Could not overwrite file.  Exiting...
  28.                ExitApp
  29.            }
  30.        }
  31.        ; Write file to disk.
  32.        FileAppend, % myBlock, % mySelectedFile
  33.    }
  34. }
« Last Edit: August 14, 2012, 10:17:00 AM by skwire » Logged

Stoic Joker
Honorary Member
**
Posts: 5,260



View Profile WWW Give some DonationCredits to this forum member
« 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
Pages: [1]   Go Up
  Reply  |  New Topic  |  Print  
 
Jump to:  
   Forum Home   Thread Marks Chat! Downloads Search Login Register  

DonationCoder.com | About Us
DonationCoder.com Forum | Powered by SMF
[ Page time: 0.107s | Server load: 0.19 ]