Page 1 of 1 1
Topic Options
#11264 - 2001-08-08 06:21 PM Removing of a line in a txt file.
Anonymous
Unregistered


Is there a way to physically remove a particular line in a file?

I'm able to search for a line in a particular file but sometimes i need to remove it to be replaced by another one.
I thought that the substr command would be helpful but it removes string in my variables not directly in the file as i would like.

Is there a way to do that?
One solution that i tried is to use the command readline to read every line of the txt file and put it in a single variable. From there i could substr the data i don't want and put back the final data in the txt file. But this don't seem a good solution since the txt file will become larger and larger with time. Well it's an avenue that i thought but that i do not like. There must be a simpler way.

Here is a sample of the test script i made. I hope this can give you an idea of my work even if it's not working well right now:

; *** Recherche dans la base de données pour savoir si la station existe déjà ***
; *** si elle n'existe pas, le technicien en service reçoit un mail ***
; *** lui indiquant qu'un nouveau PC est maintenant sur le réseau ***

$string = "@wksta"
If Open(1,$database) = 0
$line = ReadLine(1)
While @ERROR = 0
If InStr($line,$string)
$ancien = $line
$find = 1
EndIf
$line = ReadLine(1)
Loop
$q=Close(1)
EndIf

; *** Vérification si le PC qui est analysé est nouveau sur le réseau ou non ***
; *** S'il est nouveau, le préposé à l'équipement reçoit un e-mail à cette fin ***
If $find = 1
If $ancien = $nouveau
? "$ancien"
? "$nouveau"
? "same data, nothing happens"
Goto end
Else
? "different data, put new data in database and remove the old one"
; IT'S HERE THAT I DON'T HAVE THE SOLUTION TO REMOVE THE STRING AND PUT A NEW ONE
Open (1,$database,5)
WriteLine (1,$nouveau + Chr(13) + Chr (10))
$q = Close (1)
$subs = SubStr($ancien,0,0)
? "$subs"

EndIf
Else
? "$nouveau"
Open (1,$database,5)
WriteLine (1,$nouveau + Chr(13) + Chr (10))
$q = Close (1)
EndIf
:end
Del $file
Del $ini
quit

Thank you
Have a nive day

Frédéric Giguère

Top
#11265 - 2001-08-08 06:25 PM Re: Removing of a line in a txt file.
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Frédéric,

maybe this willl help : write config.nt

Jochen

_________________________



Top
#11266 - 2001-08-08 08:44 PM Re: Removing of a line in a txt file.
Anonymous
Unregistered


tks jpol for the URL you gave me.

There is something i don't understand tough:
In the mail you sent in the URL showed above, you write that we:
"can't edit files with KIX, the only thing you can do is to write the contents of the file to change in a temp file and change the line you want, then delete the input file and rename the temp file"
If i inderstand well, it means that you get ALL the data of the original file in the temp AND during the process you erase the uncorrect line for the new one.
If i used your script well, all i have left on the new config.nt is one line: files=200. Everything else is lost.

Did i missed something here?

Dag

Top
#11267 - 2001-08-09 09:14 AM Re: Removing of a line in a txt file.
Jochen Administrator Offline
KiX Supporter
*****

Registered: 2000-03-17
Posts: 6380
Loc: Stuttgart, Germany
Dag,

this must be then abuse !?!

if I run this Script here I get a complete config.nt with the changed line 'files = 200'

The part in the script that counts is :

code:

if instr($x,"files=20")
$ = WriteLine(2,"files=200" + $cr)
else
$ = WriteLine(2,$x + $cr) ;here is the 'recreation'
endif

hth

Jochen

_________________________



Top
#11268 - 2001-08-09 03:50 PM Re: Removing of a line in a txt file.
Anonymous
Unregistered


I effectively missed something here!

It's working real fine now...
I did'nt understood that this line was the central part of the recreation of the file and i did'nt wrote it the same as you...
Did'nt even realized that when i rechecked my script...

Well thanks again jpols it's sincerely appreciated and let me go hide under a rock now...

Dag

Top
#11269 - 2001-10-24 07:56 AM Re: Removing of a line in a txt file.
MCA Offline
KiX Supporter
*****

Registered: 2000-04-28
Posts: 5152
Loc: Netherlands, EU
Dear Frederic,

In topic
http://kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic&f=1&t=002936
we are also changing the config file.
In this topic you will read some possible problems when you are using f.e. WriteProfileString
in a windows 9x environment and it will prevent that same statement will be
duplicated in your file.
Information can give you some ideas.
greetings.

_________________________
email scripting@wanadoo.nl homepage scripting@wanadoo.nl | Links | Summary of Site Site KiXforms FAQ kixtart.org library collection mirror MCA | FAQ & UDF help file UDF kixtart.org library collection mirror MCA | mirror USA | mirror europe UDF scriptlogic library collection UDFs | mirror MCA

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 664 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.051 seconds in which 0.023 seconds were spent on a total of 12 queries. Zlib compression enabled.

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