Forum Moderators: bakedjake
Say I have a file at /home/mysite/babes.txt
babes.txt contains:
Britney Spears
Jessica Simpson
Hilary Duff
How do I run a command to appeand to this text file without creating duplicate entries everytime I run it?
Say I want to add 'Anna Kournikova' to the list.
How can I run a command to appeand to it and even if I run it many times there will not be duplicate entries of Anna?
How can I run a command to appeand to it and even if I run it many times there will not be duplicate entries of Anna?
Just don't duplicate "Anna", "Anna Kournikova", the first name, or the first and last names of whatever is being appended? The code would be a little different depending on what exactly it is that you need to do?
I mean don't duplicate anna kournikova.
I don't want a code that just append to the list like if I run a code to append to the list 5 time we are going to have
Britney Spears
Jessica Simpson
Hilary Duff
Anna Kournikova
Anna Kournikova
Anna Kournikova
Anna Kournikova
Anna Kournikova
Probably we can do a delete command first to delete Anna Kounikova if it exist, then we append to it,
This way we will not have too many Anna Kournikova in the list.
Sugarcane, does that code prevents duplicates?
Im going to try it anyway.
What do you think is the best solution guys?
egrep -q "^$1$" babes.txt ¦¦ echo "$1" >> babes.txt
The first "babes.txt" is what you're checking, the second is what you're appending to. So, if you wanted to check newbabes.txt and append to babes.txt, you'd have
egrep -q "^$1$" newbabes.txt ¦¦ echo "$1" >> babes.txt
Why you'd need to do that, I'm not sure, your original question wanted the same file, this solution doesn't need an intermediate file.
Sean