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

DonationCoder.com Software > Post New Requests Here

IDEA - how to capitalise the first word of every line

<< < (3/4) > >>

BigVent:
Notes:

* We can only assume that the OP has one single file.
* I ran this new script on a 105,400 line txt file.  It returned in 1800 ms. (txt file is 6525 KB)
* Fixed leading white spaces... under the assumption that the OP had leading white spaces on lines.
* Target's method used is a little faster. Since it's a "once and done" project either method should suffice.
Anyway, Good Luck stormproof!


--- Code: Autohotkey ---#NoEnv#SingleInstance, forceSetWorkingDir %A_ScriptDir%SetBatchLines, -1 ;// OP -> "The book I scanned and OCR'd had all the songs as blocks, with capitals only at the beginning of a sentence.";// We can only assume it's ONE single fileFileSelectFile, SelectedFile, 3, , Open a file, Text Documents (*.txt; *.doc)if SelectedFile ={    MsgBox, You didn't select a file.                exitapp}else{        FileRead, orig_str, %SelectedFile%        loop, parse, orig_str, `n, `r        {                if (A_LoopField != "")                {                        word_array := StrSplit(A_LoopField, A_Space)                                                ;// fixed leading whitespace but is ONLY an assumption that one exists                        ;// IF there's not a white space                        if (word_array[1] != "")                        {                                str := word_array[1]                                StringUpper,str,str,T                                word_array[1] := str                        }                        else                        {                                str := word_array[2]                                StringUpper,str,str,T                                word_array[2] := str                        }                                                ;// Rebuild the string and append to temp_var                        loop % word_array.MaxIndex()                        {                                if (word_array[a_index] = "")                                        continue                                temp_var .= word_array[a_index] " "                        }                        temp_var .= "`n"                }        }} IfExist, Output_File.txt        FileDelete, Output_File.txtFileAppend, %temp_var%, Output_File.txt Run, Output_File.txt  exitapp        esc::        critical        exitappreturn

MilesAhead:
We can only assume that the OP has one single file.
--- End quote ---
Why would you jump to that conclusion?  He says he scanned a thousand songs.  I'd say it was a safer assumption that he has 1000 files.

sed was made for this kind of stuff.  Even back in Dos people were more comfortable with command line piping and redirection.. stringing tools together.  Since everything Gui people have to load it in a window or there's some discomfort.

Edit:  I downloaded the installer, the topmost download in the list, "Complete package, except sources" from here: http://gnuwin32.sourceforge.net/packages/sed.htm

It installed on Windows 8.  I added the folder where sed.exe lives to the PATH.  sed --help in a command prompt shows the help. Supposedly everything it needs to run is in the installer.  It's good to have for cases where an already debugged one-liner may save you a ton of work.  :)

BigVent:
 :huh:

"Why would you jump to that conclusion?  He says he scanned a thousand songs.  I'd say it was a safer assumption that he has 1000 files." - MilesAhead
--- End quote ---

"I'm creating a hymn book. The book I scanned and OCR'd had all the songs as blocks, with capitals only at the beginning of a sentence." - OP
--- End quote ---

He didn't say I scanned *several* books... but "THE BOOK".  Ergo, my assumption.  I could ask why you thought he had thousands of items and call you out on the boards for poorly reading what he wrote... but frankly I don't care.


It's good to have for cases where an already debugged one-liner may save you a ton of work.
--- End quote ---

That's awesome!  Perhaps I learned something from my 15 minutes of work on this script.   8)

MilesAhead:
He didn't say I scanned *several* books... but "THE BOOK".  Ergo, my assumption.  I could ask why you thought he had thousands of items and call you out on the boards for poorly reading what he wrote... but frankly I don't care.

--- End quote ---

It's no big deal.  I'm just arguing for my position.  :)  The reason I think he's likely to have multiple files is my assumption that each page scanned will automatically be saved to a file. It's just an assumption.  But sed will work either way.. one file or a thousand.

Perhaps I learned something from my 15 minutes of work on this script.   8)


--- End quote ---
  Linus does have some awesome tools.  I keep telling myself to get into vim editor.  But I end up surfing the boards instead.  :)  Eventually I'll tackle it though.  It's too powerful to ignore forever.  :)

TaoPhoenix:
It's no big deal.  I'm just arguing for my position.  :)  The reason I think he's likely to have multiple files is my assumption that each page scanned will automatically be saved to a file. It's just an assumption.  But sed will work either way.. one file or a thousand.
-MilesAhead (December 12, 2013, 05:20 PM)
--- End quote ---

Just a random comment.

There's no assumptions when dealing with "scanning". The three rough options are "single file", "single page", and "...other".

Even my junk scanner and certainly the pro-grade one at work lets you batch pages! So no need to have single page files!

But neither would I raw-scan everything to a single file! First, that tends not to be the Way-of-part-of-the-Web.

Chapter scanning is becoming really popular - small enough to parse both on production and people side, but more than a page.

So one vote here for multi files, just not 1000 - maybe 17-30.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version