Computing.Net > Forums > Unix > check duplicate entries

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

check duplicate entries

Reply to Message Icon

Name: ohuang
Date: March 23, 2009 at 12:01:24 Pacific
OS: AIX
Subcategory: General
Comment:

Hello,
Before I am writing a record to a file, I'd like to check to see if that recrod already exists in the file. If it is already in the file, the record will be ignored, otherwise it will be writen to the file. I tought that this is going to be a simple solution by using "grep" but I couldn't get it to work. here is a sample input record:
"ouh 123 ouhlaptop"

I was trying to use grep -q command to see if the entire line above is in the file but it didn't work.

Please help!



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: March 23, 2009 at 12:21:17 Pacific
Reply:

Without seeing your script, it's hard to tell what your problem is. But a possible problem is you are trying to grep a file that is presently open for writing, i.e.:

while true
do
   .
   .
   .
done < inputfile > outputfile

In the above example, you might be greping the outputfile for something that the script previously wrote, but the shell is still buffering data so grep doesn't see it. All the data is completely written to the file until the while loop completes.

If you post your script, I'll give you an opinion.


0
Reply to Message Icon

Related Posts

See More






Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: check duplicate entries

remove duplicate entries www.computing.net/answers/unix/remove-duplicate-entries/7704.html

How to delete duplicate lines ?? www.computing.net/answers/unix/how-to-delete-duplicate-lines-/8277.html

Identify duplicate records in UNIX www.computing.net/answers/unix/identify-duplicate-records-in-unix/5892.html