Help with Unix commands

Hi, I have the following file called addresses, (it is a large file i have only copy and pasted few of the data below) and I am wanting to write a command so it will Find the ratio of mobile (07....) to land line (01....) telephone numbers?

then find the most popular first name and list the telephone numbers of everyone with that name.
sample data:

Richard:Richards:88 Birch Grove:01264290192
Jenny:Taylor:217 Victoria Place:07337349573
Jim:Jones:337 Wilmslow Road:07404751140
Richard:Richards:88 Birch Grove:01264290192
Jenny:Taylor:217 Victoria Place:07337349573
Jim:Jones:337 Wilmslow Road:07404751140

If anyone could help me, would be a great help, thank you

---------- Post updated at 08:22 PM ---------- Previous update was at 08:15 PM ----------

I have got this far with the first part of my question, but obv that out puts every entry individually and doesnt give me a ratio style output (eg.35:30)

this is what i got :
awk -F':' '{count[$4]++}END{for(j in count) print j ":" j, "("count[j]")"}' addresses

Ratio:

awk -F':' ' $NF ~/^01/ { land++; next}  $NF~/^07/ { mobile++} 0
             END{ printf(" land to mobile = %.2f \n",  land/(land + mobile) ) }' inputfile 

This sound like homework to me. We have a homework forum just for this.

1 Like

ratio of mobile to land line

awk -F : '{a[substr($NF,1,2)]++}END {print " ratio of mobile to land line is ", a["07"]/a["01"]}' infile

 ratio of mobile to land line is  2

the most popular first name and list the telephone numbers

 awk -F : 'NR==FNR{a[$1]++; m=(a[$1]>m)?a[$1]:m;next}{if (a[$1]==m) print $1,$NF |"sort"}' infile infile

Jenny 07337349573
Jenny 07337349573
Jim 07404751140
Jim 07404751140
Richard 01264290192
Richard 01264290192
1 Like