Sponsored Content
Top Forums UNIX for Beginners Questions & Answers Help getting a code in awk - Want to know how much of the data is covered by entries Post 303037838 by rdrtx1 on Wednesday 14th of August 2019 01:46:11 PM
Old 08-14-2019
Code:
awk '
NR > 1 {
   if (!id1[$2]++) {ids[idc++]=$2; len[$2]=$4;}
   for (i=$5; i<$6; i++) if (!value[$2,i]++) coverage[$2]++;
}
END {
   for (i=0; i<idc; i++)
      printf "%d --- %d / %d = %.3f\n", ids[i],
             coverage[ids[i]], len[ids[i]],
             (coverage[ids[i]] / len[ids[i]]);
}
' data

Note: for first line there is only one range of coverage. Check the range in output shown.

Last edited by rdrtx1; 08-14-2019 at 08:54 PM.. Reason: efficiency++
This User Gave Thanks to rdrtx1 For This Post:
 

We Also Found This Discussion For You

1. Shell Programming and Scripting

awk code to ignore the first occurence unknown number of rows in a data column

Hello experts, Shown below is the 2 column sample data(there are many data columns in actual input file), Key, Data A, 1 A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 I need the below output. Key, Data A, 2 A, 2 A, 3 A, 1 A, 1 A, 1 (2 Replies)
Discussion started by: ks_reddy
2 Replies
MongoDB::OID(3pm)					User Contributed Perl Documentation					 MongoDB::OID(3pm)

NAME
MongoDB::OID - A Mongo ObjectId SYNOPSIS
If no "_id" field is provided when a document is inserted into the database, an "_id" field will be added with a new "MongoDB::OID" as its value. my $id = $collection->insert({'name' => 'Alice', age => 20}); $id will be a "MongoDB::OID" that can be used to retreive or update the saved document: $collection->update({_id => $id}, {'age' => {'$inc' => 1}}); # now Alice is 21 To create a copy of an existing OID, you must set the value attribute in the constructor. For example: my $id1 = MongoDB::OID->new; my $id2 = MongoDB::OID->new(value => $id1->value); Now $id1 and $id2 will have the same value. Warning: at the moment, OID generation is not thread safe. SEE ALSO
Core documentation on object ids: <http://dochub.mongodb.org/core/objectids>. ATTRIBUTES
value The OID value. A random value will be generated if none exists already. It is a 24-character hexidecimal string (12 bytes). Its string representation is the 24-character string. METHODS
to_string my $hex = $oid->to_string; Gets the value of this OID as a 24-digit hexidecimal string. get_time my $date = DateTime->from_epoch(epoch => $id->get_time); Each OID contains a 4 bytes timestamp from when it was created. This method extracts the timestamp. TO_JSON my $json = JSON->new; $json->allow_blessed; $json->convert_blessed; $json->encode(MongoDB::OID->new); Returns a JSON string for this OID. This is compatible with the strict JSON representation used by MongoDB, that is, an OID with the value "012345678901234567890123" will be represented as "{"$oid" : "012345678901234567890123"}". AUTHOR
Kristina Chodorow <kristina@mongodb.org> perl v5.14.2 2011-09-07 MongoDB::OID(3pm)
All times are GMT -4. The time now is 03:47 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy