LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Remove duplicate data from a txt file

Solved!
Go to solution

Hi, I'm working with a VI which creates a txt file and it saves usernames (without password) but the problem is that this VI repeats the username, I mean if there are three people, Rose Jones, Sean Díaz and Rose Miles, the VI is going to write Rose, Sean, Rose. I need something that avoid or cancell writing same data until this person write something like RoseM.

0 Kudos
Message 1 of 9
(4,235 Views)
You'll have to read your text file into memory and check for duplicates before adding more data.
0 Kudos
Message 2 of 9
(4,224 Views)

As already stated, you will need to read the entire file.  I would recommend using a Set to store the values in.  If you then try to add a duplicate value, the set will not update.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 3 of 9
(4,215 Views)

The way you implement this depends on how you collect and store the data when you are looking for duplicates.

 

Can you provide the following info?

  • Is the data structure forced (i.e. First Name, Last Name or is his one string?).
  • Can this format change or is it fixed through a different interface?
  • Could someone put their first name last and last name first?
  • Do you need to check for that?
  • Do you want to force a format (i.e. The first letter of the first and last name are always capitalized)
  • Do you have an example file you are trying to update. This helps with understanding how you are storing your data.
  • What would you most ideal situation be for the end result?
Tim
GHSP
0 Kudos
Message 4 of 9
(4,197 Views)
  • It's not forced, you can write Rose Miles, RoseM, Rose, Rose_Miles, etc...
  • This format it's only used in this part of the VI and also the name list is for show a list where you can select your profile and work in your session.
  • Just Select your profile from the list, and the list shows the duplicated names
  • Not really 🙂 I just need that the user don't repeat his nickname
  • Here is the VI I didn't create it, It was created by other person before me.
  • I Just need the user name and then create his personal folder. This last step it's completed

 Sorry, I'm beginner with LabView

0 Kudos
Message 5 of 9
(4,170 Views)
Solution
Accepted by JoshX10

Instead of the Set File Position, use Read Text File.  Right-click on it and choose to "Read Lines".  Set the number of lines to read to -1.  This will read all of the lines and return an array of the lines.  You can then use Search 1D Array to see if the new user is a duplicate.  If it is, do not add it to the file and do whatever other rejections are required.  If it is not a duplicate, add it to the file.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 9
(4,158 Views)

I tried what you said but I think I did something wrong. I can't identify what it is, because I try to put the same name and the VI duplicated it again.

I send I picture.

0 Kudos
Message 7 of 9
(4,123 Views)
Solution
Accepted by JoshX10

You are setting the file pointer to the end and then read everything from there.  But you are at the end, so you will read nothing.  So just remove the Set File Position.  Now after the read is done, the file pointer will be at the end of the file, so you can just write your additional value from there.  You really should close the file after the case structure.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 8 of 9
(4,087 Views)
Solution
Accepted by JoshX10

Thank you so much! Additionaly, I had connected User+enter insted of user, and that's why, at first your, solution didn't work, but now It works 🙂

0 Kudos
Message 9 of 9
(4,036 Views)