I have large lists of information I'm manipulating. I'm using notepad because the formatting makes lists very easy to work with. I've searched the forums and Google™ and have not found a solution. I'm sorry if this is a duplicate.
I'd like to work into my script the ability to remove blank lines in the text. It now looks like:
Blah, blah 43636753 05/01/1964
Blah, blah 45636443 05/01/1964
And I want that empty line removed:
Blah, blah 43636753 05/01/1964
Blah, blah 45636443 05/01/1964
This is my third day using AHK and I absolutely love it. My boss loves it because it's saved many hours of repetative work. I'm trying to figure out the scripting but it's been a looong time since I've dabbled in coding of any kind.
Thank you so much for your help here and in the rest of the forum.
Detect and delete blank lines in notepad
Started by
Redeemed07
, Jun 18 2009 08:46 PM
6 replies to this topic
#1
-
Posted 18 June 2009 - 08:46 PM
Try this:
ControlGetText,text,Edit1,ahk_class Notepad Loop,parse,text,`n, `r If (A_LoopField!="") newText.=A_LoopField "`r`n" ControlSetText,Edit1,%newText%,ahk_class Notepad
#2
-
Posted 18 June 2009 - 08:54 PM
SCRIPT: Dim lngValue1
Dim lntValue1
Dim lntValue2
Dim lntValue3
Dim strGeneratedFilePath
Dim strDirPath
Dim strDistrictCode
Dim strIndustryCode
Dim strCurrentDate
Dim strpcbdate
Dim strpcbtime
Dim fileSys
Dim fileText
Dim strPath
Dim intAppend
Dim getName
Dim strKILNString
Dim time1
lngValue1=HmiRuntime.SmartTags("AI_2").Value
If lngValue1 ="null" Or lngValue1="" Then lntValue1 =0 Else lntValue1=lngValue1 End If
lntValue2=FormatNumber(lntValue1,2)
lntValue3= Right("00" & lntValue2, 5)
strDirPath = "D:\stack_pollution\"
strDistrictCode ="gntr"
strIndustryCode="bcltgdp"
strCurrentDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2)
strpcbdate = Right("0" & DatePart("m",Date),2)& "/" & Right("0" & DatePart("d",Date),2)& "/" & DatePart("yyyy",Date)
time1 = Right("0" & Time, 11)
strpcbtime =Left(time1,5)& ":00" & Right(time1,3)
'* Generate file path
strGeneratedFilePath = strDirPath & "stack" & strCurrentDate & ".txt"
'* Constant for appending the file
intAppend = 8
'* Create the string to be printed to the file
strKILNString = strDistrictCode& "," & strIndustryCode & ",2," & strpcbdate & " " & strpcbtime & "," & lntValue3 & ",NA,NA,NA"
'* Create the file and print the text string
Set fileSys = CreateObject("Scripting.FileSystemObject")
If fileSys.FileExists(strGeneratedFilePath) Then
Set fileText = fileSys.OpenTextFile(strGeneratedFilePath,intAppend,True)
fileText.WriteLine(strKILNString)
fileText.Close()
Else
Set fileText = fileSys.CreateTextFile(strGeneratedFilePath,True)
strPath= fileSys.GetAbsolutePathName(strGeneratedFilePath)
getName = fileSys.GetFileName(strPath)
fileText.WriteLine(strKILNString)
fileText.Close()
End If
Dim lntValue1
Dim lntValue2
Dim lntValue3
Dim strGeneratedFilePath
Dim strDirPath
Dim strDistrictCode
Dim strIndustryCode
Dim strCurrentDate
Dim strpcbdate
Dim strpcbtime
Dim fileSys
Dim fileText
Dim strPath
Dim intAppend
Dim getName
Dim strKILNString
Dim time1
lngValue1=HmiRuntime.SmartTags("AI_2").Value
If lngValue1 ="null" Or lngValue1="" Then lntValue1 =0 Else lntValue1=lngValue1 End If
lntValue2=FormatNumber(lntValue1,2)
lntValue3= Right("00" & lntValue2, 5)
strDirPath = "D:\stack_pollution\"
strDistrictCode ="gntr"
strIndustryCode="bcltgdp"
strCurrentDate = DatePart("yyyy",Date) & Right("0" & DatePart("m",Date),2) & Right("0" & DatePart("d",Date),2)
strpcbdate = Right("0" & DatePart("m",Date),2)& "/" & Right("0" & DatePart("d",Date),2)& "/" & DatePart("yyyy",Date)
time1 = Right("0" & Time, 11)
strpcbtime =Left(time1,5)& ":00" & Right(time1,3)
'* Generate file path
strGeneratedFilePath = strDirPath & "stack" & strCurrentDate & ".txt"
'* Constant for appending the file
intAppend = 8
'* Create the string to be printed to the file
strKILNString = strDistrictCode& "," & strIndustryCode & ",2," & strpcbdate & " " & strpcbtime & "," & lntValue3 & ",NA,NA,NA"
'* Create the file and print the text string
Set fileSys = CreateObject("Scripting.FileSystemObject")
If fileSys.FileExists(strGeneratedFilePath) Then
Set fileText = fileSys.OpenTextFile(strGeneratedFilePath,intAppend,True)
fileText.WriteLine(strKILNString)
fileText.Close()
Else
Set fileText = fileSys.CreateTextFile(strGeneratedFilePath,True)
strPath= fileSys.GetAbsolutePathName(strGeneratedFilePath)
getName = fileSys.GetFileName(strPath)
fileText.WriteLine(strKILNString)
fileText.Close()
End If
#4
-
Posted 20 February 2012 - 04:53 AM
Awesome code
F11::
ControlGetText,text,Edit1,ahk_class Notepad
Loop,parse,text,`n, `r
If (A_LoopField!="")
newText.=A_LoopField "`r`n" C
ControlSetText,Edit1,%newText%,ahk_class Notepad
return
But how do I scan a notepad file & remove the blank lines ?
Eg: if my notepad file is in C:\test.txt
Pls help
Alan
#5
-
Posted 14 April 2013 - 06:11 PM
Alangar Manickam, Bangalore, India
F11:: FileSelectFile,file,,,,*.txt If !file return Loop,Read,%file% If (A_LoopReadLine!="") newText.=A_LoopReadLine "`r`n" C MsgBox,4,Replace File?,Are you sure you want to remove empty lines in %file%? IfMsgBox No return FileDelete,%file% FileAppend,%newText%,%file% return
#6
-
Posted 15 April 2013 - 02:16 AM
F11:: FileSelectFile,file,,,,*.txt If !file return Loop,Read,%file% If (A_LoopReadLine!="") newText.=A_LoopReadLine "`r`n" C MsgBox,4,Replace File?,Are you sure you want to remove empty lines in %file%? IfMsgBox No return FileDelete,%file% FileAppend,%newText%,%file% return
Thank you so much HotKeyit.
#7
-
Posted 20 April 2013 - 07:58 PM
Alangar Manickam, Bangalore, India