Page 1 of 1 1
Topic Options
#212191 - 2016-12-28 12:14 PM Delete empty line from a text file
Crayven Offline
Fresh Scripter

Registered: 2016-12-27
Posts: 5
Loc: France / Le Mans
I find this post; and it 's really what i need !!
I have a .txt where a vbs delete 2 random lines .
This is a file in which 2 known administrator account names are cleared so as to only keep those that are unauthorized and unknown.

Example:
-After filling in c:\Admins.txt :
Admaster
Administrateur
Administratec
Administrator
Administratsrv

-After wiping:
Admaster

Administratec

Administratsrv

I want find this more or less 3 lines and take this in one line with ";" to separe string.
in batch there is : findstr /v "^$" "c:\Admins.txt" > c:\toto.txt


Edited by Crayven (2016-12-28 02:49 PM)
_________________________
It is at the foot of the wall that one sees best the wall

Top
#212195 - 2017-01-09 08:56 AM Re: Delete empty line from a text file [Re: Crayven]
Mart Moderator Offline
KiX Supporter
*****

Registered: 2002-03-27
Posts: 4672
Loc: The Netherlands
Untested but this looks like it should do the job. The only thing that need to be changed is the path and names of the files with all admin names and the output file.

 Code:
Break on

;set path and name of file with all admin names including empty lines
$alladminnames = "C:\AllAdminNames.txt"
;set path and name of file with cleaned up admin names excluding empty lines
$cleanedadminnames = "C:\CleanedAdminNames.txt"

;open file with all admin names including empty lines for reading
$rc = Open(1, $alladminnames, 2)
;open file with cleaned up admin names excluding empty lines for writing
$rc = Open(2, $cleanedadminnames, 5)

;read first line from file with all admin names
$line = ReadLine(1)
;check if there was an error (end of file for example)
While Not @ERROR
	;check if line in not empty
	If Trim($line) <> ""
		;check if output variable is not empty to prevent ;name1;name2;....
		If $admins <> ""
			;add line to output variable
			$admins = $line
		Else
			;add ; and line to output variable
			$admin = $admins + ";" + $line
		EndIf
	EndIf
	;read next line from file with all admin names
	$line = ReadLine(1)
Loop

;write output variable to file with cleaned up admin names
$rc = WriteLine(2, $admins)

;close file with all admin names including empty lines
$rc = Close(1)
;close file with cleaned up admin names excluding empty lines
$rc = Close(2)
_________________________
Mart

- Chuck Norris once sold ebay to ebay on ebay.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 259 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.048 seconds in which 0.022 seconds were spent on a total of 14 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org