Get records which contend same value in specific colunm


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get records which contend same value in specific colunm
# 1  
Old 12-01-2014
Get records which contend same value in specific colunm

Gents.

Please a help.

I have this input

I will like to count how many times is repeated the record which have always the values 14 and 98 only.

Code:
1000   1              
1000   1              
1001   1              
1001   1              
1002   98             
1002   98             
1002   98             
1002   98             
1003   1              
1003   1              
1003   1              
1003   1              
1004   14             
1004   14             
1004   1              
1004   1              
1005   1              
1005   1              
1005   98             
1005   98             
1006   14             
1006   14             
1006   14             
1006   14             
1007   1              
1007   11             
1007   1              
1007   14             
1008   98             
1008   98

And I will like to get this output.

Code:
value 1002 4 times repeated with value 98 only   
value 1006 4 times repeated with value 14 only   
value 1008 2 times repeated with value 98 only

Thanks for your help
# 2  
Old 12-01-2014
Try
Code:
awk '$2 ~ /14|98/  {key[$1,$2]++} END{for (i in key) {split (i, T, SUBSEP);print T[1]":" key[i]" times repeated with status " T[2]}}' file
1008:2 times repeated with status 98
1006:4 times repeated with status 14
1005:2 times repeated with status 98
1007:1 times repeated with status 14
1002:4 times repeated with status 98
1004:2 times repeated with status 14

This User Gave Thanks to RudiC For This Post:
# 3  
Old 12-01-2014
Dear RudiC
Thanks again for your help
The record 1005 has values 1 and 98 , same situation for
Record 1007 Wich have values 1,11 and 14.
My objective is to get only the records Wich have only the values 98 and 14
If the same record has any diferent status should don't list
Thanks a lot for your help
# 4  
Old 12-01-2014
Aaah - I think I got you now - after puzzling quite a while over it. Am I right to assume that once a status OTHER than 14 or 98 appears for a given key, wipe out all the key's records including the 14/98 ones?
This User Gave Thanks to RudiC For This Post:
# 5  
Old 12-01-2014
Dear RudiC

That's why I Say from the input I should get only the following

Code:
value 1002 4 times repeated with value 98 only   
value 1006 4 times repeated with value 14 only   
value 1008 2 times repeated with value 98 only


I don't need the others records,

Thanks again
# 6  
Old 12-01-2014
How about
Code:
awk     '$2 !~ /14|98/  {D[$1]}
                        {key[$1,$2]++}
         END            {for (i in key) {split (i, T, SUBSEP)
                                         if (!(T[1] in D)) print T[1]":" key[i]" times repeated with status " T[2]}}
        ' file
1008:2 times repeated with status 98
1006:4 times repeated with status 14
1002:4 times repeated with status 98

This User Gave Thanks to RudiC For This Post:
# 7  
Old 12-01-2014
Great your are genius ,
Thanks a lot,
That is what I was looking for
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find records with specific characters in 2 nd field

Hi , I have a requirement to read a file ( 5 fields , ~ delimited) and find the records which contain anything other than Alphabets, Numbers , comma ,space and dot . ie a-z and A-Z and 0-9 and . and " " and , in 2nd field. Once I do that i would want the result to have field1|<flag> flag can... (2 Replies)
Discussion started by: ashwin3086
2 Replies

2. Shell Programming and Scripting

Shell for displaying specific records from a line.

Input file. GMDCOM.27936 : Process Request <36812974> GMDCOM.27936 : Process Request <36812985> GMDCOM.27936 : Process Request <36812986> GMDCOM.27936 : Process Request <36812987> GMDCOM.27936 : Process Request <36812996> GMDCOM.27936 : Process Request <36812998> GMDCOM.27936 : Process... (14 Replies)
Discussion started by: ghosh_tanmoy
14 Replies

3. UNIX for Dummies Questions & Answers

Turning to SED to select specific records

Hi All, I am looking for a simple concise solution most likely using sed to process the following 4 rows of data from the same record and only keeps it if the second record satisfy certain critea such as surname matches up to smith or jackson: John (firstname) Smith (surname) ... (21 Replies)
Discussion started by: gjackson123
21 Replies

4. Shell Programming and Scripting

Need a very specific awk command for parsing records

I have data in a file where the first line of the file identifies the fields. I need to be able to parse out any single record, field-by-field, with the fields identified. So if my file looks like this: NAME, ADDRESS, PHONE Jim Smith, 123 Main Street, 999-888-7777 Bob Jones, 555 Park Avenue,... (6 Replies)
Discussion started by: Finja
6 Replies

5. Shell Programming and Scripting

Specific Header after every 30 records

Hi All, I have got a requirement. I have a source file, EMPFULL.txt and I need to split the data for every 30 records and place a Typical Header as below with system and page number too. 2012.01.03 Employee Dept Report 1... (6 Replies)
Discussion started by: srk409
6 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

count characters in specific records

I have a text file which represents a http flow like this: HTTP/1.1 200 OK Date: Fri, 23 Jan 2009 17:16:24 GMT Server: Apache Last-Modified: Fri, 23 Jan 2009 17:08:03 GMT Accept-Ranges: bytes Cache-Control: max-age=540 Expires: Fri, 23 Jan 2009 17:21:31 GMT Vary: Accept-Encoding ... (1 Reply)
Discussion started by: littleboyblu
1 Replies

8. Shell Programming and Scripting

cut specific records from a file

I am trying to cut the first 10 characters from a file only if the file has 'xyz' in field 185-188. I tried this cat filename | cut -c1-10 but this gives me all the records regardless of what is in field 185-188. Is this doable ? Thanks in advance for responses. (2 Replies)
Discussion started by: jxh461
2 Replies

9. Shell Programming and Scripting

Extarct specific records from wide file

I have a file which is 5 million records. And each records has 412 fields has delimited by "|". So that makes each records to be 2923 bytes long. I wanted to extract specific records like top 100 or 2500 - 5000, 50001 - 10000 etc. from this file. I tried using head command for top 100 records,... (1 Reply)
Discussion started by: acheepi
1 Replies

10. Shell Programming and Scripting

How do I insert into a specific colunm using sed

I am trying to edit my /etc/shadow file globally to make each line change from: rrrtest:BBBuhiD49QA:12881:::::: rtest1:.GHXbqSCYU:12935:::::: To rrrtest:BBBuhiD49QA:12881::90:90::: rtest1:.GHXbqSCYU:12935::90:90::: I only want to change those columns. Any help or guidance would be... (7 Replies)
Discussion started by: tercex11
7 Replies
Login or Register to Ask a Question