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

<< < (2/4) > >>

rjbull:
This particular task can probably be done fairly easily using awk.  A 'nawk' (for new awk) executable may not need the bash environment.  I'm not sure as there have been several Windows releases and i'm sure some changes in the Linux tools ported.-MilesAhead (December 11, 2013, 10:30 AM)
--- End quote ---
I've always used Gnu AWK for Windows, gawk.  Try Gawk for Windows.  The slightly older version I have doesn't need a shell.  I presume this version does what you need; I've found some variation between implementations in the past.

BigVent:
 Modify as needed.  :Thmbsup:

HTH's



--- Code: Autohotkey ---#SingleInstance, force ;//replace this string with your fileread, string, ...;//FileRead, orig_str, C:\My Documents\My File.txt  ;//<== if this is used then the "join" just below this needs to be deleted;//*from here*orig_str=(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.whereas I want to put a capital at the start of every line. there are just under a thousand songs so I don't want to do it by hand!! any ideas?  I've looked on line and can't find anything except via MS Word, which can be configured to do it after every carriage return.but as far as I can see, only as you type. is there a way to replace every "carriage return" with "carriage return and capitalise the next letter"?);//*To here* msgbox, Original text used:`n`n`n%orig_str% loop, parse, orig_str, `n, `r{        if (A_LoopField != "")        {                word_array := StrSplit(A_LoopField, A_Space)                                                        str := word_array[1]                StringUpper,str,str,T                                                word_array[1] := str                                loop % word_array.MaxIndex()                {                        temp_var .= word_array[a_index] " "                }                temp_var .= "`n`n"        }} msgbox, Final Result:`n`n`n%temp_var%  exitapp esc::criticalexitapp

Target:
post removed cos I somehow duplicated it (WTF?)

Target:
this is a bit clumsy cos I just dashed it off quickly, but instead of entering the text into the script, loop through the files.  

And instead of looping through each line, just work with the requisite strings (should be faster)


--- ---#singleinstance, force
setbatchlines, -1

fileselectfolder, myfolder, *%a_workingdir%

loop, %myfolder%\*.txt,0,1
{
tooltip, %a_index% - %a_loopfilename%
newfile:= a_loopfilename
stringreplace, newfile, newfile, `., _.,all

loop,read, %myfolder%\%a_loopfilename%
{
stringleft, xx, a_loopreadline,1
stringupper, xx, xx
stringtrimleft, yy, a_loopreadline, 1
tmp_.= xx . yy . "`n"
}

fileappend, %tmp_%, %myfolder%\%newfile%
tmp_:=
}

input files must be text, and output will be to a new file ie output from SOURCEFILE.TXT will be to SOURCEFILE_.TXT

MilesAhead:
The ahk solutions ignore the case of leading white space on a line.  One could use trim or regex to get around it.  But the advantage of stream editor is you don't have to mess with the file details.  Command line redirection inside a batch and you're done.  The only chore is coming up with the pattern replacement string(never my strong point.)  Plus I'm inclined to think it's resource efficient.  Open a command window and kick it off to run in background.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version