Jump to content

Removal of empty rows from a text file

Recommended Posts

... one of possible ways:

#include <FileConstants.au3>

$handle = FileOpen("BlankLines.txt") ; open file (read mode)
$sContent = FileRead($handle) ; read content

Do ; remove double carriage-returns (white lines)
    $sContent = StringReplace($sContent, @CRLF & @CRLF, @CRLF)
Until Not @extended

$handle = FileOpen("No_BlankLines.txt", $FO_OVERWRITE) ; write result in a new file
FileWrite($handle, $sContent)


small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By FrancescoDiMuro
      Good morning community!
      I am working on a script which read from a text file ( .txt ) and should import all the content in a SQLite3 DB, in order to execute some queries that should be difficult to execute on a text file.
      So, I was looking for something very very fast, because the file could be very large ( I don't know exaclty how much can became big, but I know a lot of rows, it's a log file ... )
      I found the "Import method", but I don't know If I can implement it in a query ( @jchd, it's your turn!  )
      Do you know some methods that I can implement in my script to have a very very fast import of thousands and thousands rows in a SQLite3 DB?
      Thanks a lot
    • By olmanRvr
      I have a compiled script :-timeStampSecs.exe which returns timestamp in seconds. I call it in FileWrite to write the time stamp in a text file.But it writes some other values instead of the timestamp. Please help.
      The script is below:-
      $kNum=run("timeStampSecs.exe","",1); also tried with flags 2,4,8,10 $hFile=FileOpen("timeStamp.txt",2) FileWrite($hFile,"the key is: "&$kNum) FileClose("$hFile") ;Code of thetimeStampSecs.exe:- ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; #include <Date.au3> Func secFromEpoch() Local $ts=_DateDiff( "s","1970/01/01 00:00:00",_NowCalc()) $ts=String($ts) ConsoleWrite("timeStamp is: "&$ts&@CRLF) Return $ts EndFunc secFromEpoch()  
    • By kneze
      Hi all,
      i would like to enter a vlaue to Inputbox 1 an press button1. Script should search value in a text file and put value after "; " to Inputbox 2.
      #cs ---------------------------------------------------------------------------- AutoIt Version: Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <file.au3> $Form1 = GUICreate("Form1", 257, 119, 192, 124) $Input1 = GUICtrlCreateInput("Input1", 15, 35, 121, 21) $Input2 = GUICtrlCreateInput("Input2", 15, 60, 121, 21) $Button1 = GUICtrlCreateButton("Button1", 145, 35, 75, 25) GUISetState(@SW_SHOW) $iLines = _FileCountLines(@ScriptDir & "\data.txt") ;MsgBox(0, "Char read:", $ilines) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Button1 EndSwitch WEnd can anyone help?
       I've been going through all of the help files and examples, but I feel lost. I can't seem to find what I need. Essentially, what I'm doing is simple(in my head).
      Create a file based on the information needed, select a line in that file, then put that line back in DOS. My code is below, I know it's messy, but I'll take the heat if you can help.
      ;BitlockerUpdate ;2016.05.24 HotKeySet("{ESC}", "Terminate") Run("C:\Windows\System32\CMD.exe") ;open command prompt Sleep(500) ;sleep half second if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("C:") Send("{ENTER}") send("CD{SPACE}%windir%\sysnative\") send("{ENTER}") EndIf ;create file with Bitlocker Protectors Send("manage-bde.exe{SPACE}-protectors{SPACE}-get{space}c:{space}>{Space}%userprofile%\Desktop\protectors.txt") ;send code "manage-bde -protectors -get c: > %userprofile%\Desktop\protectors.txt" Send("{ENTER}") ;send enter key to create text file on desktop with protectors Sleep(1000) ;sleep one second(1s) ;edit txt file/create array, pull line and paste into new file, copy text then paste into cmd window below ;update data if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("manage-bde.exe{SPACE}-protectors{SPACE}-adbackup{SPACE}c:{SPACE}-id{SPACE}{COPIEDINFORMATIONGOESHERE}") Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf ;remove files if ProcessExists("cmd.exe") Then winactivate("Administrator: C:\Windows\System32\CMD.exe") ;refocus command prompt Send("DEL{SPACE}%userprofile%\Desktop\protectors.txt") ;send code to delete protectors.txt Send("{ENTER}") ;don't forget to delete temp file if you create one created. EndIf MsgBox(0,"Done","Copy and upload are done. Please check Computer in AD.") Func Terminate() Exit 0 EndFunc  
      The protectors.txt file looks like this:
      BitLocker Drive Encryption: Configuration Tool version 6.1.7601 Copyright (C) Microsoft Corporation. All rights reserved. Volume C: [OSDisk] All Key Protectors TPM: ID: {0000000-0000-0000-0000-0000000} Numerical Password: ID: {1000000-1000-1000-1000-1000000} Password: 000000-000000-000000-000000-000000-000000-000000 Data Recovery Agent (Certificate Based): ID: {2000000-2000-2000-2000-2000000} Certificate Thumbprint: 1111111a1aa1a1aa1a1a1a1aaaaaa1aaa1 I would specifically need the line after Numerical Password. 
      Original line:      ID: {1000000-1000-1000-1000-1000000}
      Needed information: -ID: {1000000-1000-1000-1000-1000000}
      I apologize in advance for inconveniencing anyone with my silly issues. Hopefully this can stand as a great learning experience for both me and anyone else looking.
    • By CaptainSparky
      Hello good friends of Autoit, so I am making a chatbot using Autoit but I got stuck on this part:
      I already have stringright($var,stringlen($var) - stringlen(" = ") - StringInStr($var," = ") + 1) the program is made to read a text file and extract from a specific line the text after = and before =, for example:
      example line of text file: something = okay this is a text
      and I needed to extract the right part (which I already have done) and the left part (which I need help with) so how can you make stringleft to get all text before "="?
      Thanks in advance.
      Here's my code if you need it:
      #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Misc.au3> #Include <Array.au3> Global $BrainLocation = @ScriptDir & "\brain.txt" Global $FormName = "Project Lisa" Global $ReatInput = "null" Global $Memory[100] Global $BrainLineCount = 1 Global $Random[100] Global $RandomCount = 0 Global $SplitInput[100] Global $BrainCount = 0 Loader() Func Loader() Global $Form = GUICreate($FormName, 417, 279, 192, 124) Global $Output = GUICtrlCreateEdit("", 8, 8, 401, 225, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_WANTRETURN,$WS_HSCROLL),0) Global $Input = GUICtrlCreateInput("", 104, 240, 209, 21) GUISetState(@SW_SHOW) ControlFocus($FormName,"",$input) HotKeySet("{ENTER}","SendText") Main() EndFunc func Main() While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd EndFunc Func SendText() $ReatInput = GUICtrlRead($Input) GUICtrlSetData($Output,@CRLF & "You > " & $ReatInput,1) CreateRandoms() EndFunc Func CreateRandoms() While $RandomCount <> 100 $Random[$RandomCount] = Random(1,$RandomCount,1) $RandomCount += 1 WEnd $RandomCount = 0 BrainLoader() EndFunc Func BrainLoader() $ReatBrain = FileReadLine($Brainlocation,$BrainLineCount) $BrainStringRight = stringright($ReatBrain,stringlen($ReatBrain) - stringlen(" = ") - StringInStr($ReatBrain," = ") + 1) MsgBox(0,"",$Brainstringright) $BrainStringLenRight = Stringlen($brainstringright) MsgBox(0,"",$Brainstringright) $BrainActualString = 0 + $BrainStringLenRight - 10 MsgBox(0,"",$BrainActualString) $test = StringLeft($ReatBrain,$brainactualstring) MsgBox(0,"",$test) $BrainSplitedStrings = StringSplit($BrainStringRight,",") If $BrainSplitedStrings[1] <> "" Then $_1 = "true" $BrainCount += 1 EndIf If $ReatInput = $BrainActualString Then $BrainRan = Random(1,$braincount) GUICtrlSetData($output,@CRLF & "Lisa > " & $BrainSplitedStrings[$BrainRan],1) $BrainLineCount = 1 Main() Else main() EndIf $BrainLineCount += 1 BrainLoader() EndFunc
  • Create New...