Sponsored Content
Top Forums Shell Programming and Scripting Awk numeric range match only one digit? Post 302569822 by meridionaljet on Tuesday 1st of November 2011 04:26:54 PM
Old 11-01-2011
Quote:
Originally Posted by Corona688
Try comparing $2 as a number, not a regex.

Code:
awk 'BEGIN { MIN=1; MAX=9; }
($2 >= MIN) && ($2 <= MAX)'

The { print $0 } is redundant if all you want is print $0. That's what happens by default given no code block.

---------- Post updated at 01:38 PM ---------- Previous update was at 01:36 PM ----------

Also, if you have -v, that's a safer and simpler way to get variables into awk:

Code:
awk -v MIN=1 -v MAX=9 '($2 >= MIN)&&($2 <= MAX)'

Thank you very much. This is the framework I needed.
This User Gave Thanks to meridionaljet For This Post:
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

numeric range comparisons

I have two files.And a sort of matrix analysis. Both files have a string followed by two numbers: File 1: A 2 7 B 3 11 C 5 10 ...... File 2: X 1 10 Y 3 5 Z 5 9 What I'd like to do is for each set of numbers in the second file indicate if the first or second number (or both) in... (7 Replies)
Discussion started by: dcfargo
7 Replies

2. Shell Programming and Scripting

match range of different numbers by AWK

if the column1 and 2 in both files has same key (for example "a" and "a1") compare each first key value(a1 of a) of input2 (for example 1-4 or 65-69 not 70-100 or 44-40 etc) with all the values in input1. if the range of first key value in input2 is outof range in input1 values named it as out... (54 Replies)
Discussion started by: repinementer
54 Replies

3. Shell Programming and Scripting

awk to match a numeric range specified by two columns

Hi Everyone, Here's a snippet of my data: File 1 = testRef2: A1BG - 13208 13284 AAA1 - 34758475 34873943 AAAS - 53701240 53715412File 2 = 42MLN.3.bedS2: 13208 13208 13360 13363 13484 13518 13518My awk script: awk 'NR == FNR{a=$1;next} {$1>=a}{$1<=a}{print... (5 Replies)
Discussion started by: heecha
5 Replies

4. Programming

Perl : Numeric Range Pattern Matching

hi Experts just wondering if you can help me check a number between a specific range if i have an ip address , how can i say the valid number for ip between 1 to 254 something like this if ($ip ) =~ /.../ { } what the pattern i need to type thanks (3 Replies)
Discussion started by: doubando
3 Replies

5. Shell Programming and Scripting

awk length of digit and print at most right digit

Have columns with digits and strings like: input.txt 3840 3841 3842 Dav Thun Tax Cahn 146; Dav. 3855 3853 3861 3862 Dav Thun Tax 2780 Karl VI., 3873 3872 3872 Dav Thun Tax 3894 3893 3897 3899 Dav Thun Tax 403; Thun 282. 3958 3959 3960 Dav Thun Tax 3972 3972 3972 3975 Dav Thun Tax... (8 Replies)
Discussion started by: sdf
8 Replies

6. Shell Programming and Scripting

Zipping files by numeric name range

Hi there, Not being too up on bash shell programming at this point, could anyone throw me a bone about how to zip up a set of numerically-named files by range? For example, in a folder that contains files 1.pdf through 132000.pdf, I'd like to zip up just those files that are 50000.pdf and... (6 Replies)
Discussion started by: enwood
6 Replies

7. Shell Programming and Scripting

awk to update specific value in file with match and add +1 to specific digit

I am trying to use awk to match the NM_ in file with $1 of id which is tab-delimited. The NM_ will always be in the line of file that starts with > and be after the second _. When there is a match between each NM_ and id, then the value of $2 in id is substituted or used to update the NM_. Each NM_... (3 Replies)
Discussion started by: cmccabe
3 Replies

8. Shell Programming and Scripting

Get range out using sed or awk, only if given pattern match

Input: START OS:: UNIX Release: xxx Version: xxx END START OS:: LINUX Release: xxx Version: xxx END START OS:: Windows Release: xxx Version: xxx ENDHere i am trying to get all the information between START and END, only if i could match OS Type. I can get all the data between the... (3 Replies)
Discussion started by: Dharmaraja
3 Replies

9. Shell Programming and Scripting

awk to print text in field if match and range is met

In the awk below I am trying to match the value in $4 of file1 with the split value from $4 in file2. I store the value of $4 in file1 in A and the split value (using the _ for the split) in array. I then strore the value in $2 as min, the value in $3 as max, and the value in $1 as chr. If A is... (6 Replies)
Discussion started by: cmccabe
6 Replies

10. UNIX for Beginners Questions & Answers

I need to find in a file a list of number where last two digit end in a range

I all I am tryng to find a way to sort a list of number in a file by the value of last two digit. i have a list like this 313202320388 333202171199 373202164587 393202143736 323202132208 353201918107 343201887399 363201810249 333201805043 353201791691 (7 Replies)
Discussion started by: rattoeur
7 Replies
PARAM(3)						   BSD Library Functions Manual 						  PARAM(3)

NAME
param -- common parameters SYNOPSIS
#include <sys/param.h> size MAX(size a, size b); size MIN(size a, size b); DESCRIPTION
The <sys/param.h> header includes some common definitions and macros specific to NetBSD. The header is perhaps best characterized as a ker- nel equivalent of <sys/types.h>. The following list summarizes the provided definitions and macros. o First and foremost, the header defines the version of NetBSD. This is defined as #define __NetBSD_Version__ 599004800 /* 5.99.48 */ The general format is ``MMmmrrpp00'', where 'MM' and 'mm' denote the major and minor version, respectively, 'rr' is provided for compatibility, and 'pp' defines the patch level. o Common utility macros such as MAX() and MIN() as well as more specific macros such as STACK(9), ctod(9), mstohz(9), roundup(9), and setbit(9). o Numerous miscellaneous definitions such as limits, constants for the kernel memoryallocators(9), scale factors used by the sched- uler, kthread(9) priorities, and many others. o Definitions provided for historical and compatibility reasons. Examples range from definitions such as ``#define BSD'' to old pri- ority levels used in the kernel. SEE ALSO
bitops(3), cdefs(3), types(3), unistd(3) HISTORY
A <param.h> header appeared already in the Version 4 AT&T UNIX. BSD
April 10, 2011 BSD
All times are GMT -4. The time now is 09:09 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy