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