[SOLVED] count occurrences of numbers between specific values
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
count occurrences of numbers between specific values
Hi all,
I have 4018 files each has the latitude and longitude coordinates of daily weather reports, what I would like to do (if possible) is to calculate the number of weather stations within a region for each file. For example all points between latitude -20 and -10 and longitude -70 and -50. Each file (daily report) has a variable number of records
Help us to help you. Provide a sample input file (10-15 lines will do). Construct a sample output file which corresponds to your sample input and post both samples here. With "Before and After" examples we can better understand your needs and also judge if our proposed solution fills those needs.
What I would like is to get the number of occurrences that I have on the second column within -20 and -10 AND on the third column within -70 and -50, that might bring 6, since this is the number of records that match my request
Nice clean solution. However, your problem statement suggests there is more to be done.
You cited "the number of occurrences." This awk enumerates lines which meet certain criteria but does not count them.
You wrote of "the number of weather stations within a region." Where are those weather stations? Are their coordinates (latitude and longitude) in another file? What defines the size and shape of a region? Is a region rectangular or within a specified radius around each station?
awk has good arithmetic capabilities and the solution to a more complex problem could be built around a sequence of them.
and that gives me what I was looking for, because the region is a rectangle and what I need is to know how many stations do I have in that particular region latitude min=-20, latitude max=-10, longitude min=-70, longitude max=-50. The file content are each station's latitude/longitude, so by counting how many meet this criteria, I'm obtaining my goal, to know for each day (each file) how many reporting stations do I have.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.