Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8867451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:02:02+00:00 2026-06-14T17:02:02+00:00

I have got a problem i am trying to solve using ONLY awk. I

  • 0

I have got a problem i am trying to solve using ONLY awk.

I have a csv file in the structure:

Easting  Northing    Latitude    Longitude   Locality Name

Easting  "Northing"  "Latitude"  "Longitude"     "LocalityName"
364208  176288           51.48441   -2.51685     "Fishponds"
358596  172813           51.45278   -2.59726     "Bristol City Centre"
358886  177828           51.49789   -2.59367     "Southmead"
358839  177839           51.49798   -2.59435     "Southmead"
358980  177882           51.49838   -2.59232     "Southmead"
359009  177863           51.49821   -2.5919          "Southmead"
358839  177529           51.4952        -2.59431     "Southmead"
359475  168262           51.41192   -2.58409     "Hengrove Park"
358945  173526           51.45921   -2.59232     "Bristol"
358943  173525           51.4592    -2.59235     "Bristol"
358941  173524           51.45919   -2.59238     "Bristol"
358940  173523           51.45919   -2.59239     "Bristol"
358945  173528           51.45923   -2.59232     "Bristol"
358936  173520           51.45916   -2.59245     "Bristol"
358936  173521           51.45917   -2.59245     "Bristol"
358932  173516           51.45912   -2.5925          "Bristol"

etc… I am trying to write an awk script which will count each instance of Locality name and the print print this so an out put would be:

Fishponds 1
Bristol City Centre 1
Southmead 5
Hengrove park 1
Bristol 8

So far i have got this:

BEGIN { i = 0; state = 0; names[NR]; FS=","; }

{
#for each element in names array, check if already exists.
    for(j=0;j<=i;j++)
    {
        if(names[j] == $5)
        {
        state = 1;
        break;
        }
    }
# If the name doesnt already exist add to names array
    if(state == 0)
    {
        names[i] = $5;
        i++;
    }
    state = 0;
}

END { 
    for(x=0;x<=i;x++)
    {
    print names[x];
    }
}

Which hopefully sorts the locations and removes the duplicates, but i still cannot think of a good way to count the instances of each location then list them back.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:02:03+00:00Added an answer on June 14, 2026 at 5:02 pm

    Simpler soulution:

    awk -F '"' 'NR>3 {locname[$2]++}
                END { for (n in locname) {print n, locname[n] } }' INPUTFILE
    

    First the input file separator is set to ", so the second field will be the location name. Skipping the first line (header). Utilizing an array (key is the second field) to count the occurrences. After the last line print the array’s keys, and values.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to solve this problem all day but haven't got any
have a nice day. I got problem when trying to create an image from
Got a problem with a query I'm trying to write. I have a table
I am trying to solve this problem : https://www.spoj.pl/problems/CERC07S/ I have identified that i
Trying to solve a very simple problem using mvvm-light, but after days of sifting
I have an interesting problem that I'm trying to solve and was wondering if
Hi i have a JSP file , while trying to add code i got
I have got a problem to get back a parameter from my view to
I have got a problem with calling a global function, which takes a pointer
I have got a strange problem about in_array recently which I cannot understand. e.g.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.