o
k
q
u
e
s
t
i
o
n
s
.
c
o
m

[02/03] Delete Lines from a file without writing a new file -

Hello everyone! I am new to these forums. Before posting, I searched through the threads to see if someone had a problem like I did, but I had no luck. If i post something that someone else already asked about I apologize...Anyways to my question.

I am working on a port security application that needs to use a lot of file manipulation like Reading/Writing, etc, but I can't seem to find any good examples of how to delete a line from a text file without writing a new file or to the same file. Here is some general information about the application:

The first application monitors "real time log file" for port security shutdowns and writes those lines to a another text file named (portsecurity.txt) based on a "keyword(s)". That works great.

The next application reads each line from (portsecurity.txt), uses reg exp to find specific words like an "IP address" and a "port number" and adds those to list box on the client interface. This works! The first thing I noticed is sometimes the same line gets copied twice, because the same port was shutdown. To avoid duplicate IP addresses and ports being placed in the listbox, I used an array to avoid the duplication. That works...

Now the tricky part. I want to remove those duplicate lines from portsecurity.txt file, but since the 1st application writes to portsecurity.txt constantly, I am not sure how to remove the duplicate lines without changing the file... i.e. read all lines in, delete portsecurity.txt, then write a new portsecurity.txt with the lines that I want.

In addition, this problem will haunt me later on...because once a user enables a port, the IP address and port will be removed from the listbox and the line that pertains to that IP address and port in portsecurity.txt will need to be removed. Hopefully I can knock out two birds with one stone.

Any suggestions on how I can do this, or is there a way to delete a line once it is read in on a streamreader without using a streamwriter?

Before messing around with files like this, I was going to use a SNMP manager, but I could not find a free library...and I wanted to avoid extra overhead.

Thanks in advance,
Mike

 

Delete new lines -
How to delete new lines from a file? Example I have a text file with 10 lines, how to make all 10 lines to be in a single line? Input: 1 2 3 4 Output: 1234


[2005] Delete few lines -
How can I delete first 15 lines from txt file? (File is too big, and speed is too important to read whole file and save it without few lines )


writing text file -
Hi. I want to have VB write to a text file. Here's what I want it to do: Insert a new line at the beginning of the file and add the data there (instead of the end) and not have more than 20 lines in the text file. For example, if it writes data to the text file and there are 20 line


[02/03] Delete Lines from a file without writing a new file -
Hello everyone! I am new to these forums. Before posting, I searched through the threads to see if someone had a problem like I did, but I had no luck. If i post something that someone else already asked about I apologize...Anyways to my question. I am working on a port security


Delete Lines -
Hey everyone have a question for ya I have a .txt file with a bunch of data that is spread out throught the document I want to write a little script that will go through this tell the bottom and look for 2 or more spaces between paragraphs and delete the spaces what code would I need t


writing/editing to specific lines of a txt file -
hey all once again. well the topic kinda describes the problem. does anyone know how to write to a specific line? wat im trying to do is search a string through the txt file and delete string. the strings in the txt file are listed all in seperate lines (eg) String1 St


Delete blank lines -
Hello, In my vb application, I am executing a shell command and receive its outputs to a text file. The output from the shell command always has 2 lines, first line of data and 2nd line of spaces. Because of this, my output text file has alternate blank lines through out the file...


Creating a log file -
Can anybody tell me how to : - Add lines at the top of a text file - Delete lines without deleting the entire file (keeping a log file 500 K for example) Later.


please help.. important -
Hi, I have a text file that I want to edit... I want to deleteall empty lines from it. I can open the file and rewrite the content (without the empty lines) to another file... but the code looks messy and SLOW! Can you please help ? Some lines are totally empty, but ot


Open a text file and count the lines in text file -
Does anybody have any good vb code that would allow me to open a file count the lines in the file (or search for a certain character and do a count of that character) close the file and then compare it to a variable count. if the count is the same then continue, if the file is not the


running batch file from VB6 -
Hello all! I am trying to run a batch file from within a VB6 program. I am first creating the batchfile by writing to a file "file.bat". The file contains two lines. When I run the batch file via Shell("file.bat"), a cmd window opens and instead of running the


Delete Multiple Lines From Text File! -
How do I delete multiple lines from a text file? Actually in my web browser project, users can add different URLs to their list of Favorites. The Favorites are written in a text file as & when they get added. Like IE, the Favorites are displayed in a menu. Users can also import


writing multiple lines to textfile -
i am a newbie in VB and i am creating a sample text file generator program that would write multiple lines of text to a text file when the button is clicked. there are around 500 lines to be written on the resulting text file. is there a way i could create the text file without havi


Writing to a log file -
This will sound really stupid but I have forgotten the syntax for this stuff.... I am trying to open a file, actually its a log file from vb6 and input some lines. I am cool with most of it but don't know how to write to it.... I am using the following: Open strfilename for append


Problem with IO.BinaryWriter.Write -
hey all, i have some problems writing and lines skiping, im trying to overwrite file 1 into file 2 but when i writing to a file, all of the data writes in one line.. why? From: File:Launcher.exe To:Launcher2.exe Size:1276998 To: File:Launcher.exeTo:Launcher2.exeSize:1276998


Truncate Ascii\Text File -
OK... there are a million posts on deleting lines from text files, but none answer my question. How do I simply delete the last 3 lines of a text file? I do not want to read the text file to a string, modify it, and write it back because the text file can be 7 - 15 megs. I need


Deleting specified line in file -
Hi, how can i delete a specified line in a file? For example i have 10 lines in a file and i want to delete the 5 line and move all the lines after one place up. thx


Kinda Database Maybe -
Two questions... 1) I am writing a login for my program.. I need to know how to make the program check to see if the username and password are in a file and how to validate using this file...... 2) In the same programming, I am putting in a tool for admins to add users and del


Deleting the spaces between lines in a file -
How do I delete the spaces between lines in a file? I want it to search for the spaces and delete them! For example, my file looks like this: hi VIP3r was here I want it to look like this: hi VIP3R was here Thanx in advance


How to detect if a file is being used by another process -
Hi, In my code I'm trying to delete a log file from the pc, but before I can delete it I have to wait for its controlling application to finish writing to it. If I try to delete it while another process is using it, I just get an error message. So, is there any way to detect if


Writefile help please -
Okay, here's what I'm trying to do. Lets say I have a file containing 1234567890 I'm writing a function to write on that file starting at a specified byte. The thing is, I want to clear the contents of the file after the specified byte, so if what I'm writing doesn't extend pas


Writefile Help -
Okay, here's what I'm trying to do. Lets say I have a file containing 1234567890 I'm writing a function to write on that file starting at a specified byte. The thing is, I want to clear the contents of the file after the specified byte, so if what I'm writing doesn't extend pas


XML Files (read,write,delete) -
Dear All Please could anyone tell me.About Xml File and reading specific record from the XML Text file and Writing new record to the XML File and deleting the specific records. Because i want to store my data to the XML File first and then from XML file store to the SQL Server and t


XML read,write,delete -
Dear All Please could anyone tell me.About Xml File and reading specific record from the XML Text file and Writing new record to the XML File and deleting the specific records. Because i want to store my data to the XML File first and then from XML file store to the SQL Server and


Removing lines from the top of a TextBox -
I am writing a telnet client and must set a maximum of lines in the main RichTextBox. The RichTextBox.Lines property does not seem to contain any property or method to delete actual lines of text. Is there any way to remove entire lines from the top of the text box?


Unable to delete a file while it's being written to -
Is there a way to detect if I can delete a file without handling a error? This has come up a few times, the last time being we have scripts we generate (replace a default username with an incremented username) and then perform another similar operation on resulting file. The problem


Secure Delete [Resolved by Alphanos] -
Hi, How can i securely delete a file in VB. I am writing an encryption utility and need to delete the source file securly after the encryption. By securly i mean, it can not be recovered easily. How can i achive that in vb. Thanks for your help. Danial


delete the last three lines -
how can i delete the last three lines from a .txt file if they was empty?


writing to file help! -
How can i keep print lines of words from a text box and save it to a file (append) ?? i only did Print #1, Text1.Text but it will only print the starting text of the textbox into the txt file. it is also possible like type in a line into the text box and i click


read-write-save txt file -
Hi Guys, ( used VB-6 ) Opening file, no problem here. Adding next lines to existing file creating me a problem. To fully open file with all lines in it works OK. 1. Dim sFileText as String 2. Dim iFileNo as Integer 3. iFileNo = FreeFile 4. 'open the file for re


Writing a file -
I'm stuck. I have this php code that basically loops through a file and puts it all in a variable. But is there a way to save that variables info to a new file or in an existing one??? <?php $lines = file('storage.xml'); $vars = ""; foreach ($lines as $line_n


Deleting the whole sequential file -
Hi, I am trying to delete out a whole sequential access file. I am writing a webbrowser program and want the user to be able to add favorites to a folder or delete the folder (sequential access file). I can get everything inside of it deleted but not the file itself. Any suggest


large txt -
I need to delete the last 10 lines on the bottom of a large text file.....the last 10 lines are always the same but rewriting the file is out of the question any ideas?


Save the last 300 lines in a text file -
I want to open a text file. Count the lines. If the count is greater than 300 then I want to save the last 300 lines to the same file. I want to try to only have 300 lines in the text file when a program starts. I am using this file as a temporary error log and need to keep the amount


find duplicate lines in file -
i have a file hold approx 150 sentences. some of them are doubles i.e the same (exactly) is it possible to find the same repeated lines and delete the duplicate line? i will be needing a text box as i will need to save the changed data in the text box to a file.


VB & File access : QUESTION ! -
Is it possible to modify the first lines of a file without having to re-write it entirely ? ie : is it possible to modify (append / delete lines) in the 1st Mb of a 30 Mb file without having to re-write the full 30 Mb ?


Delete .rtf file in folder -
Will anyone show me how to delete a .rtf file in a folder for me? When I click the Delete button on the form, I like the to program to go into a folder which I specified the path and delete a file that matches a criteria. I'm using the SaveFileDiaglog to save the file, but I don't know


select lines form textbox -
I have a text box that receives data from one txt file, and that file as something like this: r/s w/s kr/s kw/s wait actv wsvc_t asvc_t %w %b device 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0 0 c2t6d0 0.0 1.2 0.0 8.9 0.0 0.1 21.6


Getting last few lines in text file -
I was wondering what would be the most efficient way to get the last 20 or so lines from a text file? I've noticed that it seems when using text streams fseek( file, buffer_size, SEEK_END ); doesnt work. I could iterate through the file, find out how many lines (Carriage re


how to find number of lines in a text file to insert to an array -
hi there, i have a text file with lines(it's actually a script, whom each line is doing something else). i want to put it in an array, and then manipulate each line (clean it, send it through serial port, etc.). now, i don't know how many lines are in the file... how can i find that