Sign in to follow this  
Followers 0
bafh

Check if string is alreade written?

3 posts in this topic

#1 ·  Posted (edited)

Hi folks,

well, I got a file (file1) in which are written like 1200 lines. I only need a specific value of each line, so i filtered this one with string actions (stringsplit, stringinstring and so on)

Then it writes these values to another file(file2).

Now my problem: Some of the values appear twice or even more often in file1 and thus are written twice or mor often in file2. How can i make the script check if the value was already added to file2 and, if so, continue with the next line?

Here my script:

$line=1

$file="backup.txt"

for $line=1 to 1284

$string=filereadline($file,$line)

$op1=StringSplit ($string, "Date" ,1)

$User=stringsplit($op1[2],"</B>",1)

$op2=stringsplit($User[2],"<br",1)

$total1=$User[1]&$op2[1]

$total2=StringReplace ($total1, "<i>","-")

$total3=StringReplace ($total2, "</i>","")

FileWriteLine("new file.txt",$total3)

next

Thanks

Edited by bafh

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Hi folks,

well, I got a file (file1) in which are written like 1200 lines. I only need a specific value of each line, so i filtered this one with string actions (stringsplit, stringinstring and so on)

Then it writes these values to another file(file2).

Now my problem: Some of the values appear twice or even more often in file1 and thus are written twice or mor often in file2. How can i make the script check if the value was already added to file2 and, if so, continue with the next line?

Here my script:

$line=1

$file="backup.txt"

for $line=1 to 1284

$string=filereadline($file,$line)

$op1=StringSplit ($string, "Date" ,1)

$User=stringsplit($op1[2],"</B>",1)

$op2=stringsplit($User[2],"<br",1)

$total1=$User[1]&$op2[1]

$total2=StringReplace ($total1, "<i>","-")

$total3=StringReplace ($total2, "</i>","")

FileWriteLine("new file.txt",$total3)

next

Thanks

You'd have to store the value from file1 in a variable.

Open the second file and pretty much do the same as you did before read each line and check for the value of the variable, if it does not exist then read the next line until end of file is reached, if you get to the end then you know you have to write the value to file 2, or if it does exist then jump out of the loop and continue going through file1

Edited by ChrisL

Share this post


Link to post
Share on other sites

Ye, got it!

$line=1

$file="thisfile.txt"

for $line=1 to 1284

$check=1

$string=filereadline($file,$line)

$op1=StringSplit ($string, "Access" ,1)

$op2=StringReplace($op1[2],"</B>","")

$op3=StringReplace($op2,"<i>","-")

$op4=StringReplace($op3,"</i>","")

$op5=StringReplace($op4,"<br>","")

$op6=StringReplace($op5,"&","")

$op7=StringReplace($op6,";","")

$op8=StringReplace($op7,"gt","")

$key=stringtrimright($op5,16)

$test=filereadline("test.txt")

$ok=stringinstr($test,$key)

filewrite("test.txt",$key)

If $ok=0 then filewriteline("Hello.txt",$op8)

next

Works fine B) just needs like 1 minute to do this with all the lines!

Share this post


Link to post
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
Sign in to follow this  
Followers 0