Get user id count for a range


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get user id count for a range
# 1  
Old 05-19-2012
Get user id count for a range

I have a file which has users having different values against them in second column.

I want to set a range and get the count of users in that range.

Suppose :-

a 4
b 19
c 27
d 87
e 123

And I define the range like 1-20 , 20 -50 and so on..... Please assume the range as x-y, y-z, z-w etc...

I want to count of users which lies in the specific range ?
# 2  
Old 05-19-2012
Code:
#/usr/bin/env ksh
awk '
     BEGIN {
        if( start > stop$2 )
            exit( 1 )
    }

    $2 >= start && $2 <= stop { c++ }

    END{ printf( "%d users in the range %d-%d\n", c, start, stop) }
' start="${1%%-*}" stop="${1##*-}" $2



Simple shell script. Assumes the range (start-stop) is supplied on the command line as the first parameter. Optionally the second parameter is the file to read (reads from stdin if not supplied). Small bit of error checking short circuits (prevents reading all of a large file) if the range is invalid.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Create range of values and count values.

Gents, It is possible to generate a range of values according to column 1 and count the total of rows in the range. example input 15.3 15.5 15.8 15.9 16.0 16.1 16.8 17.0 17.5 18.0 output desired 15.0 - 15.9 = 4 (10 Replies)
Discussion started by: jiam912
10 Replies

2. UNIX for Dummies Questions & Answers

Find the count of files by last created date based on the given date range

My unix version is IBM AIX Version 6.1 I tried google my requirement and found the below answer, find . -newermt “2012-06-15 08:13" ! -newermt “2012-06-15 18:20" But newer command is not working in AIX version 6.1 unix I have given my requirement below: Input: atr files: ... (1 Reply)
Discussion started by: yuvaa27
1 Replies

3. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

4. Shell Programming and Scripting

display Range of date depend on user input php

Hi, i am very new to php Is it possible to display Range of date depend on user input day example: user input 2 day start from 28/4/12 it will add 2 day from date of input so display should look like this 28/4/12 to 30/4/12 then from 30/412 user add another 4 date so will... (0 Replies)
Discussion started by: guidely
0 Replies

5. Shell Programming and Scripting

Search on date range of file based on user input

Hello I would like to ask for help with a script to search a directory that contains many log files and based on a users input after being prompted, they enter a date range down to the hour which searches the files that contain that range. I dont know how to go about this. I am hoping that the... (5 Replies)
Discussion started by: lostincashe
5 Replies

6. Shell Programming and Scripting

Count occurences of a numeric string falling in a range

Dear all, I have numerous dat files (1.dat, 2.dat...) containing 500 numeric values each. I would like to count them, based on their range and obtain a histogram or a counter. INPUT: 1.dat 1.3 2.16 0.34 ...... 2.dat 1.54 0.94 3.13 ..... ... (3 Replies)
Discussion started by: chen.xiao.po
3 Replies

7. UNIX for Dummies Questions & Answers

How to count how many numbers in a certain range?

Hi I have a data file with two columns which looks like: 1 42 2 40 3 55 4 50 5 38 6 49 7 33 8 46 9 39 10 33 11 33 12 26 13 46 14 44 15 55 16 54 17 30 18 32 (7 Replies)
Discussion started by: marhuu
7 Replies

8. UNIX for Dummies Questions & Answers

Word Count for a range of text

Help Please! I have alot of text that I would like to count for a range of text. logevents.1:<190> Oct 30 02:59:42 N/A : 6|4145|RC|CAC: Terminated logevents.1:<190> Oct 30 02:59:42 N/A : 6|4097|RC|CAC: Deleted logevents.1:<190> Oct 30 02:59:44 N/A : 6|4145|RC|CAC: Terminated ... (5 Replies)
Discussion started by: bpfoster7
5 Replies

9. Shell Programming and Scripting

Selecting files between a user inputed date range

Hi all! I'm working on a KSH script to select files between a user inputed date range (stored in a variable) and then move them and unzip them. I'm stuck at how to get the files between the user inputed date range selected. Any help would be greatly appreciated! The files are as such: ... (6 Replies)
Discussion started by: kelldan
6 Replies

10. Shell Programming and Scripting

Log File date compare for user defined range

:confused: Hi i am a noob and need a little help to finish my shell script. I am learning as i go but hit a problem. I am search thorugh logs(*.rv) files to find entires between two user defined dates, The script so far looks for the "START" and "END" of each entry at sees if it belongs To... (0 Replies)
Discussion started by: mojo24
0 Replies
Login or Register to Ask a Question