topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • Saturday December 14, 2024, 7:07 pm
  • Proudly celebrating 15+ years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Arranges in a txt file  (Read 10277 times)

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Arranges in a txt file
« on: August 12, 2012, 07:06 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

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 13,291
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Arranges in a txt file
« Reply #1 on: August 12, 2012, 07:18 AM »
You can probably just open it in Excel, then save it as a CSV.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #2 on: August 12, 2012, 09:27 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.

 :-*

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #3 on: August 12, 2012, 09:38 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 "
 :-[

iphigenie

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,170
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #4 on: August 12, 2012, 09:51 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

eleman

  • Spam Killer
  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 413
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #5 on: August 12, 2012, 10:21 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.

Ath

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 3,629
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #6 on: August 12, 2012, 12:11 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 :)

jgpaiva

  • Global Moderator
  • Joined in 2006
  • *****
  • Posts: 4,727
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #7 on: August 12, 2012, 12: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 :)
That looks like an awesome recommendation  :Thmbsup:

barney

  • Charter Member
  • Joined in 2006
  • ***
  • Posts: 1,294
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #8 on: August 12, 2012, 01:16 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  :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.

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #9 on: August 12, 2012, 05:08 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 ?

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #10 on: August 12, 2012, 05:09 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

Contro

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 3,940
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #11 on: August 12, 2012, 05:25 PM »
Not bat, but I think CSV Editor is slow.

 :-[

Any other idea ?

Best Regards

eleman

  • Spam Killer
  • Supporting Member
  • Joined in 2009
  • **
  • default avatar
  • Posts: 413
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #12 on: August 13, 2012, 12:17 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 :)

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 5,644
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #13 on: August 13, 2012, 02:52 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:

2012-08-13_17-45-51.jpgArranges in a txt file

Pressing RegexSplit will give: "first",    "second","third","fourth"

AbteriX

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 1,149
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #14 on: August 13, 2012, 01:48 PM »
Code: Text [Select]
  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


Code: Text [Select]
  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 "\" .

sword

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 200
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #15 on: August 13, 2012, 03:32 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.

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,287
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #16 on: August 14, 2012, 10:05 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.

Code: Autohotkey [Select]
  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 AM by skwire »

Stoic Joker

  • Honorary Member
  • Joined in 2008
  • **
  • Posts: 6,649
    • View Profile
    • Donate to Member
Re: Arranges in a txt file
« Reply #17 on: August 14, 2012, 11:49 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.