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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Need help finding more than one uniq value with grep script found on internet
# 1  
Old 11-18-2009
Java Need help finding more than one uniq value with grep script found on internet

SmilieSmilieSmilieSmilieSmilieSmilie

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 was 29 boxes with 51 tapes in each box. When I ran thru software my count was then 1333-146 short! I took the input file or raw scan file,
sorted and ran uniq -d > output on file. This gave me 132 tapes. 1333 + 132 = 1465 still 14 short. Then I used a windows freeware program called Agent Ransack to look up each of these duplicate tapes I created with uniq. There were 14 tapes that had were actually triplicates-hence the number of 146-I found a script on the internet to use the file I created as records and run against my BOX# file to see the box locations-but discovered it would only run if I took out the triplicates from the grep_input_file. Can someone help-please!?

Now I found a script on the internet to save the time of looking all these numbers up manually only thing it does not even run if you have 3 or more duplicate volsers of the same value.

(uniq does not care if your file has 2 or 3 more numbers of same volser-it will only find one occurence)

Here is script that only will work with 2 locations of a record.

#!/bin/sh
FILE=main_file
INPUT=grep_input_file
OUT=rpt_grep_output
> $OUT
# greps out lines from the input file and writes to output file:
for i in `cat $INPUT`
do
cat $FILE | grep -iw $i >> $OUT
done

Can anyone hack this to find more than one record from main_file
for example my duplicate file has A10001 in it.

And record A10001 is listed in main_file in three boxes
A10001,BOXA01
A10001,BOXA03
A10001,BOXA04

the program above will not even run-BUT-if I delete the record A10001,BOXA04
the script above will run.

Thanks bryan SmilieSmilie

Last edited by Linux-wannabe; 11-18-2009 at 03:11 PM.. Reason: clarification
# 2  
Old 11-21-2009
Quote:
Originally Posted by Linux-wannabe
Code:
cat $FILE | grep -iw $i >> $OUT

How about ...

Code:
grep "$i" $FILE >> $OUT

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Grep everything between two pattern if match not found

I need to help to work this Print everything between 2 patterns if grep is not found the search word example Detroit orange cat bat rat apple sed -n "/Detroit,/apple/p" d |grep chicago output would be Detroit orange cat bat rat (1 Reply)
Discussion started by: jhonnyrip
1 Replies

2. Shell Programming and Scripting

Grep and replace with found string

Hi, I need to find all rows in 1st col of one file in another file (first occurrence) and replace the 1st col of first file with the grep result (the entire line). For example search AA from file 1 in file 2 and replace in file 1 by entire line found. File1 AA BB CC DD BB AA CC DDFile2 ... (2 Replies)
Discussion started by: ritakadm
2 Replies

3. Shell Programming and Scripting

grep: not found

Hi, running below korn shell script #!/bin/ksh chk_dump() { CNT=`ls *.dmp|grep $DATE|wc -l` if ; then echo "delete_dumpfile" else echo "start_exp" fi } chk_dump getting below error: (3 Replies)
Discussion started by: milink
3 Replies

4. UNIX for Dummies Questions & Answers

Finding and Extracting uniq data in multiple files

Hi, I have several files that look like this: File1.txt Data1 Data2 Data20 File2.txt Data1 Data5 Data10 File3.txt Data1 Data2 Data17 File4.txt (6 Replies)
Discussion started by: Fahmida
6 Replies

5. Shell Programming and Scripting

Insert blank line if grep not found

Hi all, I've googling around forum regarding my prob, the nearest would same as thread tittled Insert blank line if grep not found, but she/he did not mention the solution, so I would like to request your help I've this task, to search in file2 based on pattern in file1 and output it to... (4 Replies)
Discussion started by: masterpiece
4 Replies

6. Shell Programming and Scripting

How to grep for message and if found display filename?

Hi i'm new to the forum and was hoping someone could help me with the following query. I do alot of testing and have hundreds of log files output. I have a script (someone else wrote) which finds all the passed and failed logs and puts a number in a column onto a webpage: e.g: Pass ... (4 Replies)
Discussion started by: defamer
4 Replies

7. Shell Programming and Scripting

read the first 10 lines below a keyword found by grep

Hello Everyone, i need to read specific number of lines ( always serialized ; i.e from 10 to 20 or from 34 to 44 ) in a file , where the first line is found by grep 'ing a keyword. example file.txt ------------------------------------------------------------------ --header this is the... (7 Replies)
Discussion started by: alain.kazan
7 Replies

8. Shell Programming and Scripting

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... (4 Replies)
Discussion started by: Linux-wannabe
4 Replies

9. 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

10. Shell Programming and Scripting

Insert blank line if grep not found

Hello everyone... please help if you can -- I'm stumped. Making this work will save me hours of manual labor: I need to search file2 for pattern in file1. If pattern found append file2 line to file3. If pattern not found append a blank line to file3. file1 contents example: 123 456 789... (6 Replies)
Discussion started by: michieka
6 Replies
Login or Register to Ask a Question