# Extract repetead values in date range

**URL:** <https://community.unix.com/t/extract-repetead-values-in-date-range/368113>\
**Category:** Shell Programming and Scripting\
**Created:** [August 31, 2017, 5:58am UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113 "2017-08-31T05:58:50Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [August 31, 2017, 5:58am UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/1 "2017-08-31T05:58:50Z")

</div>

Gents,

Using the following values:

```nohighlight
3687650458 08/29/2017 1.67581
3687650388 08/29/2017 1.67581
3687650330 08/29/2017 1.67581
3687650330 08/29/2017 1.67581
3687650330 08/28/2017 2.67581
3687650330 08/28/2017 2.67581
3687650330 08/27/2017 3.67581
3687650330 08/27/2017 3.67581
3687650330 08/26/2017 4.67581
3687650330 08/26/2017 4.67581
3687650330 08/25/2017 5.67581
3687650330 08/25/2017 5.67581
3687650330 08/24/2017 6.67581
3687650330 08/24/2017 6.67581
3687650330 08/23/2017 7.67581
3687649144 08/29/2017 1.67581
3687649144 08/29/2017 1.67581
3687649144 08/28/2017 2.67581
3687649144 08/28/2017 2.67581
3687649144 08/27/2017 3.67581
3687649144 08/27/2017 3.67581
3687649144 08/26/2017 4.67581
3687649144 08/26/2017 4.67581
3687649144 08/25/2017 5.67581
3687649144 08/25/2017 5.67581
3687649144 08/24/2017 6.67581
3687649144 08/24/2017 6.67581
3687649144 08/23/2017 7.67581
3686449774 08/25/2017 5.67581
3686449774 08/24/2017 6.67581
3686449774 08/24/2017 6.67581
3686449774 08/23/2017 7.67581
3685250156 08/29/2017 1.67581
3685250156 08/29/2017 1.67581
3685250156 08/28/2017 2.67581
3685250156 08/28/2017 2.67581
3685250156 08/27/2017 3.67581
3685250156 08/27/2017 3.67581
3685250156 08/26/2017 4.67581
3685250156 08/26/2017 4.67581
3685250156 08/25/2017 5.67581
3685250156 08/25/2017 5.67581
3685250156 08/24/2017 6.67581
3685250156 08/24/2017 6.67581
3685250156 08/23/2017 7.67581
3685250108 08/29/2017 1.67581
3685250108 08/29/2017 1.67581
3685250108 08/28/2017 2.67581
3685250108 08/28/2017 2.67581
3685250108 08/27/2017 3.67581
3685250108 08/27/2017 3.67581
3685250108 08/26/2017 4.67581

```

Desired output

```nohighlight
3687650330 08/23/2017 08/29/2017 7
3687649144 08/23/2017 08/29/2017 7
3685250156 08/23/2017 08/29/2017 7
3685250108 08/26/2017 08/29/2017 4

```

The required data in output are the minimum and maximum date where the same value in column is repeated during this days.. the column 3 is the difference between the 2 dates.. .

As u notice I need only the values which are more than 3 days repeated and always keep only the last date in this case

```nohighlight
08/29/2017 

```

.

Example i don't extract the value below because the repeated values are not ending with date

```nohighlight
08/29/2017 

```

.

```nohighlight
3686449774 08/23/2017 08/25/2017 3

```

Please help, thanks..

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [August 31, 2017, 6:37am UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/2 "2017-08-31T06:37:13Z")

</div>

Any attempts / ideas / thoughts from your side? You promised last time...

---

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [August 31, 2017, 9:01am UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/3 "2017-08-31T09:01:11Z")

</div>

Hi RudiC

Using the following code i get close..

```nohighlight
dt=`awk '{print $2}' tmp5 | sort -n -t"/" -k3 -k1 -k2 | tail -1`

awk ' {D1=$1
                         D2=$2
             D3=$3
                        }
         !(D1 in MIN) {MIN[D1]=D2
                         MAX[D1]=D2
             TIM[D1]=D3
                         next
                        }
          D2 < MIN[D1] {MIN[D1]=D2}
          D2 > MAX[D1] {MAX[D1]=D2}
          END {for (m in MIN) print m, MIN[m], MAX[m], TIM[m]}
        ' tmp5 | awk '{if($3 ~ "'$dt'") print}' 

```

output

```nohighlight
3685250108 08/26/2017 08/29/2017 1.67581
3687650330 08/23/2017 08/29/2017 1.67581
3685250156 08/23/2017 08/29/2017 1.67581
3687650458 08/29/2017 08/29/2017 1.67581
3687650388 08/29/2017 08/29/2017 1.67581
3687649144 08/23/2017 08/29/2017 1.67581

```

only i need to get the correct value in diff between 2 days..

Please, help.. Tks

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [August 31, 2017, 2:36pm UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/4 "2017-08-31T14:36:59Z")

</div>

Not sure I understand - what exactly is missing? And, how to get at it?

---

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [August 31, 2017, 3:14pm UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/5 "2017-08-31T15:14:14Z")

</div>

Hi RudiC

I will like to get the days diff between min and max date.

```nohighlight
3685250108 08/26/2017 08/29/2017 4
3687650330 08/23/2017 08/29/2017 7
3685250156 08/23/2017 08/29/2017 7
3687650458 08/29/2017 08/29/2017 1
3687650388 08/29/2017 08/29/2017 1
3687649144 08/23/2017 08/29/2017 7

```

thanks in advance.

---

<div class="post-metadata">

**Author:** ![RudiC](https://community.unix.com/letter_avatar/rudic/32/6_449c533f586939b6e5f246632a46421f.png) [@RudiC](https://community.unix.com/u/RudiC)\
**Post date:** [August 31, 2017, 5:59pm UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/6 "2017-08-31T17:59:46Z")

</div>

I am missing YOUR approach to calculate that required difference in your (?) attempt... howsoever, try

```nohighlight
awk '
                {DV = substr ($2, 7) substr ($2, 1, 2) substr ($2, 4, 2)
                }
!($1 in MIN) {MIN[$1] = DV
                 MAX[$1] = DV
                 MIS[$1] = $2
                 MAS[$1] = $2
                 next
                }
DV > MXDV {MXDV = DV
                }
DV < MIN[$1] {MIN[$1] = DV
                 MIS[$1] = $2
                }
DV > MAX[$1] {MAX[$1] = DV
                 MAS[$1] = $2
                }

END {for (m in MIN) if (MAX[m] == MXDV) print m, MIS[m], MAS[m], MAX[m] - MIN[m] + 1
                }
' file
3685250108 08/26/2017 08/29/2017 4
3687650330 08/23/2017 08/29/2017 7
3685250156 08/23/2017 08/29/2017 7
3687650458 08/29/2017 08/29/2017 1
3687650388 08/29/2017 08/29/2017 1
3687649144 08/23/2017 08/29/2017 7

```

---

<div class="post-metadata">

**Author:** ![jiam912](https://community.unix.com/user_avatar/community.unix.com/jiam912/32/2027_2.png) [@jiam912](https://community.unix.com/u/jiam912)\
**Post date:** [September 1, 2017, 11:31am UTC](https://community.unix.com/t/extract-repetead-values-in-date-range/368113/7 "2017-09-01T11:31:33Z")

</div>

Hello RudiC,

It works perfectly.

Thanks a lot
