uniq and grep help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting uniq and grep help
# 1  
Old 11-16-2009
Tools uniq and grep help

linux-wannabe


Sorry if this seems easy to some here-but my experiments are not working.

Say I have a file with duplicate records-how can I grep out the occurences of that file into another file. I have tried grep -F -f output original > answer and this fails.

Here is how my original file looks.

A10001,BOXA01
A10002,BOXA01
A10003,BOXA01
A10004,BOXA01
A10001,BOXA01
A10003,BOXA04

the database program I am using will take out duplicates (the first field duplicate), so I will be missing A10001 and A10003 for two labels.

(Audit tapes using a scangun and how do we know if it is a true duplicate tape or a duplicated scan-duplicates only come into play every once in a while-but more times that not when destroying tapes or moving to another location-hence the location of a box#)

I used to do something like this.

cut -c1-6 original > output
uniq -d output > duplicates

grep 'A10001' original
produces the result (output to crt-gave a 0)!!!!
A10001,BOXA01
A10001,BOXA01
or
grep 'A10003' original
A10003,BOXA01
A10003,BOXA03

or use Agent Ransack Windows Gui for free to search folders for containing text=try it MythicSoft...


I actually use berkeley utilities for dos and has uniq, grep, cut, and wc ,etc... but if need be I will try to make another "live-cd" for the road-
but this is not working for a large file of say 1000 duplicates and 10000 in original file to find the duplicates and location I need for auditing purposes-


Is there a way to take my duplicate file "known duplicate volsers" and make a batch command to run thru grep and then
redirection?

For example;

grep 'known duplicate volser' original > output

but have grep take the entire file at one time?

Any suggestions-

Like I said Linux-wannabe-I know a little bit about linux and that 8 bits is a byte.!
But to know how magic works and gcc takes more effort!!

SmilieSmilieSmilieSmilie

Last edited by Linux-wannabe; 11-18-2009 at 11:58 AM.. Reason: syntax
# 2  
Old 11-17-2009
Before provide the solution, I need know, if you got these duplicate records, which one do you need reserve? The first one, the last one, or by other rules?

Code:
A10003,BOXA01
A10003,BOXA03

# 3  
Old 11-17-2009
Try this:

Code:
awk '{ if (arr[$0]==$0) print; else arr[$0]=$0; }'  < original > duplicate

# 4  
Old 11-17-2009
Lightbulb

Quote:
Originally Posted by rdcwayx
Before provide the solution, I need know, if you got these duplicate records, which one do you need reserve? The first one, the last one, or by other rules?

Code:
A10003,BOXA01
A10003,BOXA03


Need to reserve both-use a software program that will drop
A10003,BOXA03

but lets pretend it is a real object that needs to stay

When I do an inventory I keep a count
50 boxes with 50 tapes = 2500
once we run thru software it becomes 2309 tapes (hence duplicate tapes with same volser)
but I can confirm count
is true with wc -l or opening in excel or original text file.

Thanks.
# 5  
Old 11-17-2009
Quote:
Originally Posted by dennis.jacob
Try this:

Code:
awk '{ if (arr[$0]==$0) print; else arr[$0]=$0; }'  < original > duplicate

One more approch using sort/uniq

Code:
sort file | uniq -D

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get first column value uniq

Hi All, I have a directory and sub-directory that having ‘n' number of .log file in nearly 1GB. The file is comma separated file. I need to recursively grep and uniq first column values only. I did in perl. But i wish to know more command line utilities to calculate the time for grep and... (4 Replies)
Discussion started by: k_manimuthu
4 Replies

2. UNIX for Dummies Questions & Answers

awk or uniq

Hi Help, I have a file which looks like 1 20 30 40 50 60 6 2 20 30 40 50 60 8 7 20 30 40 50 60 7 4 30 40 50 60 70 8 5 30 40 50 60 70 9 2 30 40 50 60 70 8 I want the o/p as 1 20 30 40 50 60 6 4 30 40 50 60 70 8 Is there a way I can use uniq command or awk to do this? ... (11 Replies)
Discussion started by: Indra2011
11 Replies

3. Shell Programming and Scripting

Uniq help

hello I want to check on first column duplicates and print the unique first and second columns My trial output is not generating what I needed, i.e the second column. thanks in advance (5 Replies)
Discussion started by: bhargavpbk88
5 Replies

4. Shell Programming and Scripting

Uniq not doing what I want it to

I have a master list of servers. I also have a list of servers I'm not supposed to touch. I'm trying to filter out the list servers that I'm not supposed to touch from the master list of servers, so I will have a "master list of servers I can touch". When I try to filter these I'm not getting... (4 Replies)
Discussion started by: MaindotC
4 Replies

5. Shell Programming and Scripting

uniq commmand

Hi I'm having a file (extract.txt) which contains lots of repeated values i want to extract it only with unique values,while am using the the uniq command It result's with 1510 lines this too have the duplicates,pls help me on this. I attached my extract.txt file as attachment here. ... (2 Replies)
Discussion started by: thelakbe
2 Replies

6. Shell Programming and Scripting

uniq -c

When I do uniq -c on a list of sorted numbers, for eg: 1 1 2 2 2 3 3 4 It outputs 2 1 3 2 2 3 1 4. Now, is there a way to sort on the column that "uniq -c" produced? (2 Replies)
Discussion started by: prasanna1157
2 Replies

7. Shell Programming and Scripting

Need help finding more than one uniq value with grep script found on internet

:confused::eek::cool::D:mad::) here is scenario- Scan Box # then tapes inside- Run program from raw scan and makes a newfile with volser#,BOXA01 location kind of thing... Read on... I had to destroy 1479 tapes on a pallet for destruction. Scanned each box and then tapes inside-There... (1 Reply)
Discussion started by: Linux-wannabe
1 Replies

8. UNIX for Dummies Questions & Answers

| Help | unix | grep | sort | uniq - Different output from what I thought would be the same

Hello, I'm having an consistency issue.... grep 'a' /usr/share/dict/words 1) This will highlight every 'a' in each word. grep 'a\{1,\}' /usr/share/dict/words 2) This will highlight 'a' if it occurs at least once in a sequence. So every 'a'. Output of 1) I would... (1 Reply)
Discussion started by: MykC
1 Replies

9. UNIX for Dummies Questions & Answers

Difference between plain "uniq" and "uniq -u"

Dear all, It's not entirely clear to me from manpage the difference between them. Why we still need "-u" flag? - monkfan (3 Replies)
Discussion started by: monkfan
3 Replies

10. HP-UX

help on UniQ

All, Can anybody provide me the links to the documentation on UniQPrint? I need to prepare some documents to help my co-workers to learn UniQPrint. Regards, Vishal (0 Replies)
Discussion started by: vishal_ranjan
0 Replies
Login or Register to Ask a Question