Sponsored Content
Top Forums Shell Programming and Scripting Count occurrences in first column Post 302944530 by sheemam on Wednesday 20th of May 2015 01:52:04 AM
Old 05-20-2015
This one should work.

Code:
awk 'BEGIN{h[" "]=0;max=0}{ind=-1;for(k in h)if(k==$1){ind=h[k];break}if(ind==-1){ind=++max;h[$1]=ind}print $1,ind,$2,$3}' infile

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

count occurrences and substitute with counter

Hi Unix-Experts, I have a textfile with several occurrences of some string XXX. I'd like to count all the occurrences and number them in reverse order. E.g. input: XXX bla XXX foo XXX output: 3 bla 2 foo 1 I tried to achieve this with sed, but failed. Any suggestions? Thanks in... (4 Replies)
Discussion started by: ptob
4 Replies

2. UNIX for Dummies Questions & Answers

Search and Count Occurrences of Pattern in a File

I need to search and count the occurrences of a pattern in a file. The catch here is it's a pattern and not a word ( not necessarily delimited by spaces). For eg. if ABCD is the pattern I need to search and count, it can come in all flavors like (ABCD, ABCD), XYZ.ABCD=100, XYZ.ABCD>=500,... (6 Replies)
Discussion started by: tektips
6 Replies

3. Shell Programming and Scripting

Count the number of occurrences of the word

I am a newbie in UNIX shell script and seeking help on this UNIX function. Please give me a hand. Thanks. I have a large file. Named as 'MyFile'. It was tab-delmited. I am told to write a shell function that counts the number of occurrences of the ord “mysring” in the file 'MyFile'. (1 Reply)
Discussion started by: duke0001
1 Replies

4. Shell Programming and Scripting

Help with Unix and Awk to count number of occurrences

Hi, I have a file (movies.sh), this file contains list of movies such as I want to redirect the movies from movies.sh to file_to_process to allow me process the file with out losing anything. I have tried Movies.sh >> file_to_process But I want to add the row number to the data... (2 Replies)
Discussion started by: INHF
2 Replies

5. Shell Programming and Scripting

Count occurrences in awk

Hello, I have an output from GDB with many entries that looks like this 0x00007ffff7dece94 39 in dl-fini.c 0x00007ffff7dece97 39 in dl-fini.c 0x00007ffff7ab356c 50 in exit.c 0x00007ffff7aed9db in _IO_cleanup () at genops.c:1022 115 in dl-fini.c 0x00007ffff7decf7b in _dl_sort_fini (l=0x0,... (6 Replies)
Discussion started by: ikke008
6 Replies

6. Shell Programming and Scripting

Script to count word occurrences, but exclude some?

I am trying to count the occurrences of ALL words in a file. However, I want to exclude certain words: short words (i.e. <3 chars), and words contained in an blacklist file. There is also a desire to count words that are capitalized (e.g. proper names). I am not 100% sure where the line on... (5 Replies)
Discussion started by: Cronk
5 Replies

7. Shell Programming and Scripting

How to count occurrences in a specific column

Hi, I need help to count the number of occurrences in $3 of file1.txt. I only know how to count by checking one by one and the code is like this: awk '$3 ~ /aku hanya poyo/ {++c} END {print c}' FS="\t" file1.txt But this is not wise to do as i have hundreds of different occurrences in that... (10 Replies)
Discussion started by: redse171
10 Replies

8. Shell Programming and Scripting

awk Group By and count string occurrences

Hi Gurus, I'm scratching my head over and over and couldn't find the the right way to compose this AWK properly - PLEASE HELP :confused: Input: c,d,e,CLICK a,b,c,CLICK a,b,c,CONV c,d,e,CLICK a,b,c,CLICK a,b,c,CLICK a,b,c,CONV b,c,d,CLICK c,d,e,CLICK c,d,e,CLICK b,c,d,CONV... (6 Replies)
Discussion started by: Royi
6 Replies

9. Shell Programming and Scripting

Count the number of string occurrences to display 0 entries in output

Hello Friends, Can somebody assist an issue I am having? I have a separate file with a list of account ids XXX200B02Y01 XXX200B03Y01 XXX200B05Y01 XXX200B07Y01 XXX200B08Y01 I call the file, and run an egrep against a directory and logfiles AccountID=$(cat... (2 Replies)
Discussion started by: liketheshell
2 Replies
Bio::PopGen::IO(3pm)					User Contributed Perl Documentation				      Bio::PopGen::IO(3pm)

NAME
Bio::PopGen::IO - Input individual,marker,allele information SYNOPSIS
use Bio::PopGen::IO; my $io = Bio::PopGen::IO->new(-format => 'csv', -file => 'data.csv'); # Some IO might support reading in a population at a time my @population; while( my $ind = $io->next_individual ) { push @population, $ind; } DESCRIPTION
This is a generic interface to reading in population genetic data (of which there really isn't too many standard formats). This implementation makes it easy to provide your own parser for the data. You need to only implement one function next_individual. You can also implement next_population if your data has explicit information about population memberhsip for the indidviduals. FEEDBACK
Mailing Lists User feedback is an integral part of the evolution of this and other Bioperl modules. Send your comments and suggestions preferably to the Bioperl mailing list. Your participation is much appreciated. bioperl-l@bioperl.org - General discussion http://bioperl.org/wiki/Mailing_lists - About the mailing lists Support Please direct usage questions or support issues to the mailing list: bioperl-l@bioperl.org rather than to the module maintainer directly. Many experienced and reponsive experts will be able look at the problem and quickly address it. Please include a thorough description of the problem with code and data examples if at all possible. Reporting Bugs Report bugs to the Bioperl bug tracking system to help us keep track of the bugs and their resolution. Bug reports can be submitted via the web: https://redmine.open-bio.org/projects/bioperl/ AUTHOR - Jason Stajich Email jason-at-bioperl.org APPENDIX
The rest of the documentation details each of the object methods. Internal methods are usually preceded with a _ new Title : new Usage : my $obj = Bio::PopGen::IO->new(); Function: Builds a new Bio::PopGen::IO object Returns : an instance of Bio::PopGen::IO Args : next_individual Title : next_individual Usage : my $ind = $popgenio->next_individual; Function: Retrieve the next individual from a dataset Returns : L<Bio::PopGen::IndividualI> object Args : none next_population Title : next_population Usage : my $pop = $popgenio->next_population; Function: Retrieve the next population from a dataset Returns : L<Bio::PopGen::PopulationI> object Args : none Note : Many implementation will not implement this write_individual Title : write_individual Usage : $popgenio->write_individual($ind); Function: Write an individual out in the implementation format Returns : none Args : L<Bio::PopGen::PopulationI> object(s) write_population Title : write_population Usage : $popgenio->write_population($pop); Function: Write a population out in the implementation format Returns : none Args : L<Bio::PopGen::PopulationI> object(s) Note : Many implementation will not implement this newFh Title : newFh Usage : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format') Function: does a new() followed by an fh() Example : $fh = Bio::SeqIO->newFh(-file=>$filename,-format=>'Format') $sequence = <$fh>; # read a sequence object print $fh $sequence; # write a sequence object Returns : filehandle tied to the Bio::SeqIO::Fh class Args : See Bio::SeqIO::Fh fh Title : fh Usage : $obj->fh Function: Example : $fh = $obj->fh; # make a tied filehandle $sequence = <$fh>; # read a sequence object print $fh $sequence; # write a sequence object Returns : filehandle tied to Bio::SeqIO class Args : none _load_format_module Title : _load_format_module Usage : *INTERNAL Bio::PopGen::IO stuff* Function: Loads up (like use) a module at run time on demand Example : Returns : Args : _guess_format Title : _guess_format Usage : $obj->_guess_format($filename) Function: Example : Returns : guessed format of filename (lower case) Args : perl v5.14.2 2012-03-02 Bio::PopGen::IO(3pm)
All times are GMT -4. The time now is 02:51 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy