#!/bin/bash uniq_colors=$( awk -F';' '!seen[$5]++ {if($5!="color")print($5)}' test.txt ) for i in $uniq_colors do COUNT=1 awk -v s=$i -v COUNT=$COUNT -F';' '{ if ($5==s) {{ COUNT++ } if (COUNT%2==1) {var1=sin($4)/cos($4); printf($2"\t"); printf("%.4f\n",var1)} } }' test.txt done