Jump to content

Delete blank lines


 Share

Recommended Posts

Hello,

I would like delete blank lines of files. Only 5 last lines

I used filecountlines.

And then _FileWriteToLine but the function create a new blank line...

I thinked to the function stringstripws, but i haven't find how to.

thanks

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

Hello,

I would like delete blank lines of files. Only 5 last lines

I used filecountlines.

And then _FileWriteToLine but the function create a new blank line...

I thinked to the function stringstripws, but i haven't find how to.

thanks

Hi there m8,

try this, removes ALL blanks:

#include <array.au3>

_FileReadToArray($host,$aRecords);*** (filename, array)
_arraydisplay($aRecords, "Array with blanks");Display array
while 1
    $newvar = _ArraySearch($aRecords, "", 0, 0, 0, false); Search for null lines
    if @error = 6 Then; no more matches found
        ExitLoop
    Else
        _ArrayDelete($aRecords, $newvar);Delete current full line
    EndIf
wend

_arraydisplay($aRecords, "Array without blanks");Display array

Enjoy

Cheers

Old Scriptology

Visual Ping 1.8 - Mass Ping Program with export to txt delimited.

Desktop 2 RGB and YMCK - Pick a color in the desktop and get the RGB and YMCK code.

Desktop 2 RGB - Pick a color in the desktop and get the RGB code.

ShootIT 1.0 - Screen Capture full and partial screen

[font="'Arial Black';"]Remember Remember The Fifth of November.[/font]

Link to comment
Share on other sites

Hello,

I would like delete blank lines of files. Only 5 last lines

I used filecountlines.

And then _FileWriteToLine but the function create a new blank line...

I thinked to the function stringstripws, but i haven't find how to.

thanks

#include <File.au3>
;DELITE LINES must b 54321 not 12345
_FileWriteToLine(@ScriptDir&"\test.txt", 5, "", 1)
_FileWriteToLine(@ScriptDir&"\test.txt", 4, "", 1)
_FileWriteToLine(@ScriptDir&"\test.txt", 3, "", 1)
_FileWriteToLine(@ScriptDir&"\test.txt", 2, "", 1)
_FileWriteToLine(@ScriptDir&"\test.txt", 1, "", 1)

every time you delete first line and try to delite secont problem is that second line is first becose you deleted firstone so itl skip one line basicly :/ but if you start from end line and move to the begining itl work

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 
Link to comment
Share on other sites

It's good.

I am find it.

So for delete "n" firsts lines we can do :

For $i = n To 1 Step -1
_FileWriteToLine(@ScriptDir&"\Test.txt", $i, "", 1)
NextoÝ÷ Ù©Ý~ÝzW­z«¨¶z®¢ÙZ²Û%w¬ÁçÚºÚ"µÍÜ ÌÍÚHHHÈ ÌÍÐÛÛSYÛÈHÑ[PÛÝ[[ÊØÜ   [È ][ÝÉÌLÕÝ   ][ÝÊBÑ[UÜ]UÓ[JØÜ[É][ÝÉÌLÕÝ ][ÝË  ÌÍÐÛÛSYÛË    ][ÝÉ][ÝËJB^

Thanks

Edited by jerem488

Qui ose gagneWho Dares Win[left]CyberExploit[/left]

Link to comment
Share on other sites

jerem488

Another, fast way:

$file = @ScriptDir & "\test.txt"
$sRead = FileRead($file)

$aString = StringSplit(StringStripCR($sRead), @LF)
$ResultString = ""
$count = 0

For $i = $aString[0] To 1 Step -1
    If $aString[$i] = "" Then
        $count += 1
        If $count <= 5 Then ContinueLoop
    EndIf
    
    $ResultString = $aString[$i] & @CRLF & $ResultString
Next

$hFile = FileOpen($file, 2)
FileWrite($hFile, $ResultString)
FileClose($hFile)

:mellow:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...