## Counting a consecutive number in column 2

Counting a consecutive number in column 2
# 8
02-06-2014
You're welcome. I added a modification in the END section. This all only works if column 1 is grouped..
 Scrutinizer View Public Profile for Scrutinizer Find all posts by Scrutinizer
# 9
02-06-2014
One more question

Quote:
Originally Posted by Scrutinizer
Try something like:
Sorry for bothering you. I would like to know how to get average of the number grouped by column 1.

If I have following data,

The result I would like obtain would be

 Ryan Kim View Public Profile for Ryan Kim Find all posts by Ryan Kim
# 10
02-06-2014
Try:
--edit--
I added if(NR>1) in all suggestions

Last edited by Scrutinizer; 02-06-2014 at 05:42 PM..
This User Gave Thanks to Scrutinizer For This Post:
 Scrutinizer View Public Profile for Scrutinizer Find all posts by Scrutinizer
# 11
04-08-2014
One more question, take two

Hi,
I am working with very similar data and Scrutinizer's answers have been very helpful. However, I was wondering how one would alter the output a bit. For example, if I had Ryan Kim's data in his post 'One more question':
What if I wanted to print out all of the actual lines that correspond to a series of lines with at least n consecutive values in column 2? For example, if I had n=4 (or 5) and the above data, I would want to extract and print the following lines of data:
If I had n=3, I would extract all of the lines from the original dataset.

I altered Scrutinizer's awk solution slightly to allow filtering the series based on the number of lines with consecutive values in column two:
But, I can't figure out how to print the actual series of lines with the consecutive values in them. Any possible advice/explanations would be greatly appreciated!

Thank you very much in advance for any help.

Last edited by mbp; 04-08-2014 at 02:01 AM.. Reason: typo
 mbp View Public Profile for mbp Find all posts by mbp
# 12
04-08-2014
Something like this?
 Scrutinizer View Public Profile for Scrutinizer Find all posts by Scrutinizer
# 13
04-09-2014
Great!

Hi Scrutinizer,
thanks very much, that works perfectly!
 mbp View Public Profile for mbp Find all posts by mbp

## Check/print missing number in a consecutive range and remove duplicate numbers

Hi, In an ideal scenario, I will have a listing of db transaction log that gets copied to a DR site and if I have them all, they will be numbered consecutively like below. 1_79811_01234567.arc 1_79812_01234567.arc 1_79813_01234567.arc 1_79814_01234567.arc 1_79815_01234567.arc...

## Cut counting consecutive delimiters as fields

When cut encounters consecutive delimiters it seems to count each instance as a field, at least with spaces. Is this typical behavior for any delimiter? #:~\$ ifconfig eth0 | grep HWaddr eth0 Link encap:Ethernet HWaddr 94:de:80:a7:6d:e1 #:~\$ ifconfig eth0 | grep HWaddr | cut -d " " -f...

## Delete a specific line containing non consecutive number?

Dear Specialists, I have following data 1 1 2 2 2 3 3 3 6 4 3 4 5 4 9 6 5 11 7 6 7 and I would like to obtain data like below 1 1 2 2 2 3 4 3 4 7 6 7

## Counting the number of element in each column

Hello, I have a file as follows: ENSGALG00000000189 ENSGALG00000000189 ENSGALG00000000189 ENSGALG00000000215 ENSGALG00000000215 ENSGALG00000000218 ...

## Sum every 3 consecutive numbers in a column

Dear All, I have a file with only one column. And I want to add every 3 consecutive numbers together and print the result. Input File: 21.1 10 10 55 11 99 10 8 4 Expected Output: 41.1

## Number of Consecutive Occurences

:b: Hi Folks, I have a requirement to find the number of consecutive occurences based on month. Here is the below sample of my requirement. I have say four columns CARUSERNAME BRAND_CODE MONTH YEAR Below is sample Data John|C|JAN|2013 Tim|C|FEB|2013 Tom|C|Mar|2013 Ron|C|Apr|2013...

## How to compare the values of a column in awk in a same file and consecutive lines..

I would like to compare the values of 2nd column of consecutive lines of same file in such a way so that if the difference between first value and second value is more than 100 it should print complete line else ignore line. Input File ========== PDB 2500 RTDB 123 RTDB-EAGLE 122 VSCCP 2565...

## Merge two non-consecutive lines based on line number or string

This is a variation of an earlier post found here: unixcom/shell-programming-scripting/159821-merge-two-non-consecutive-lines.html User Bartus11 was kind enough to solve that example. Previously, I needed help combining two lines that are non-consecutive in a file. Now I need to do the...

## Calculate difference between consecutive data points in a column from a file

Hi, I have a file with one column data (sample below) and I am trying to write a shell script to calculate the difference between consecutive data valuse i.e Var = Ni -N(i-1) 0.3141 -3.6595 0.9171 5.2001 3.5331 3.7022 -6.1087 -5.1039 -9.8144 1.6516 -2.725 3.982 7.769 8.88

## counting number of sentence

Hi all I want to count total numbers of sentences separated by fullstop (.) in different files under a directory at one go. Any help is appreciated.