how to find out recurrence and print it.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to find out recurrence and print it.
# 1  
Old 02-02-2012
Question how to find out recurrence and print it.

Hi all,

I have a file having data like this:
Code:
rs4332761    15XB
rs4332761    unk
rs4571228    15XB
rs457263    5XB
rs4606515    10XA
rs4606515    10XB
rs4606515    15XB

I want output like this:
Code:
rs4332761    15XB,unk
rs4571228    15XB
rs457263    5XB
rs4606515    10XA,10XB,15XB

I tried using simple regex options in notepad++ and others but not getting the exact thing. If anyone can suggest any small script or code, that will be much appreciated.

Thanks.
# 2  
Old 02-02-2012
See if this AWK helps
Code:
awk ' { a[$1] = a[$1] FS $2 }END{ for (i in a) print i a[i]}' input

This User Gave Thanks to Peasant For This Post:
# 3  
Old 02-02-2012
MySQL

Quote:
Originally Posted by Peasant
See if this AWK helps
Code:
awk ' { a[$1] = a[$1] FS $2 }END{ for (i in a) print i a[i]}' input

Thank you very much Peasant.
It worked nice. I just needed to replace space with , in output.
Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Awk, find and print

Ubuntu, Bash 4.3.48 Hi, I have this input file with many columns separated with ":" ARC=121:ERF=12244:IDE=2334:ADA=34 .... ERF=124:ARC=123:IDE=2344:ADA=54 .... ERF=16254:IDE=2434:ADA=78:ARC=134 .... and I want this: ARC=121:IDE=2334 ARC=123:IDE=2344 ARC=134:IDE=2434 I need to... (5 Replies)
Discussion started by: echo manolis
5 Replies

2. Shell Programming and Scripting

awk to find text and print value

In the attached file I am using awk to skip the header row, search for specific text, and print particular values that are next to it all from the same field. awk FNR > 1 '$79 == "Bases in target regions"":" "Number of amplicons"': "Target bases with no strand bias"':" {print $79}' >... (1 Reply)
Discussion started by: cmccabe
1 Replies

3. UNIX for Dummies Questions & Answers

Find the missing file and print

Hi , i will be getting 24 files for one day with a formate like 20131028_01 - 20131028_24 kind of ,i am trying to write a shell script to count the number of files and if the count is not equal to 24 print the missing files names for A in `seq 0 23`; do ls *20131024_`printf "%02d" $A`*;... (3 Replies)
Discussion started by: vikatakavi
3 Replies

4. Shell Programming and Scripting

Find and print Modification

Hi All I am stuck with a problem and i want your help. I have a file in which content of that file looks like-: <tr> <td><A HREF="http://333.33.333.33:3333/">Pan Eligibility</A></td> <td>NNNNNNNN_NS</td> <td>333.33.333.33</td> <td>3333</td> <td><p... (7 Replies)
Discussion started by: parthmittal2007
7 Replies

5. Shell Programming and Scripting

Find x and print its record

Hi all, I have a file containing two fields with 154 rows/records/lines (forgive me, my UNIX terminology is not quite up to par yet). I am trying to read from this list, find a value (lets say 0), then print the record/line/row that value falls on (In this case it would be record/line/row #27)?... (5 Replies)
Discussion started by: StudentServitor
5 Replies

6. Programming

Find and print number after string in C

I'm trying find and print a number after a specific user passed string in each line of a text file using C (as requested by the powers that be). I've pieced together enough to read the file, find the string and print the line it was found on but I’m not sure where to even start in terms of finding... (3 Replies)
Discussion started by: cgol
3 Replies

7. Shell Programming and Scripting

Find longest string and print it

Hello all, I need to find the longest string in a select field and print that field. I have tried a few different methods and I always end up one step from where I need to be. Methods thus far: nawk '{if (length($1) > long) long=length($1); if(length($1)==long) print $1}' The above... (6 Replies)
Discussion started by: SEinT
6 Replies

8. Shell Programming and Scripting

awk to print count for chars recurrence

input: 123456 1111 124567 2222 125678 3333 234567 aaaa 456789 abcd awk logic: - read lines for recurring 1st 2 chars of the 1st field - if recurrence detected count up and print value output: 1 123456 1111 2 124567 2222 3 125678 3333 (6 Replies)
Discussion started by: ux4me
6 Replies

9. Shell Programming and Scripting

recurrence for every sunday for Date::MAnip in perl

Hi, I have a requirement to define all Saturdays/Sundays of every month in a year as holidays. I am making use of Date::Manip package available in perl. I tried writing a recurrence as : 0:1*3:7:0:0:0 --> this relation helps me to define 3rd Sunday of a year as sunday. My requirement is... (1 Reply)
Discussion started by: harpreetanand
1 Replies

10. UNIX for Dummies Questions & Answers

How to Find /replace and print?

Hi, I have one txt file, and I want replace 2 diffrent texts with somther text and the same time, I want to send that to print.. something like sed -e 's/Times-Roman/Helvetica/'|sed -e 's/Times/Helvetica/' oldfile > newfile < lp is this will workout? any idea? (1 Reply)
Discussion started by: redlotus72
1 Replies
Login or Register to Ask a Question