ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Arranges in a txt file

<< < (4/4)

sword:
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:
How can I find a script for doing this works and many other similars ?-Contro (August 12, 2012, 07:06 AM)
--- End quote ---

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 ---sFile = %1% ; Dropped filename path.If ( sFile ){    FileRead, myData, % sFile    Loop, Parse, myData, `n, `r    {        ; Strip out extra whitespace.        myLine := RegExReplace( A_LoopField, ",\s+(\w)", ",$1" )        ; Replace all commas with quotes-comma-quotes.        StringReplace, myLine, myLine, `,, "`,", All        ; Rebuild file, adding quotes at the beginning and end        ; of each line.        myBlock .= """" . myLine . """`r`n"    }    ; Ask user to save file.    FileSelectFile, mySelectedFile, S16, % sFile, Save as...,    If ! ( ErrorLevel ) ; User did not cancel, proceed.    {        ; 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 FileExist( mySelectedFile )        {            FileDelete, % mySelectedFile            If ( ErrorLevel ) ; Basic sanity check to see if the file deleted.            {                MsgBox, 16, Error!, Could not overwrite file.  Exiting...                ExitApp            }        }        ; Write file to disk.        FileAppend, % myBlock, % mySelectedFile    }}ExitApp

Stoic Joker:
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.-eleman (August 12, 2012, 10:21 AM)
--- End quote ---

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.

Navigation

[0] Message Index

[*] Previous page

Go to full version