Classify value to a range


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Classify value to a range
# 1  
Old 07-05-2011
Classify value to a range

Dear All,
I need to classify my data into sets or ranges based on values in the second column of a file as - low medium and high.

INPUT:

file1.dat
1.tmp 1.03
2.tmp 0.38
3.tmp 3.23
4.tmp 1.34

I would like to classify all the numerical values into a range based on the followng cutoffs:

1> as low (L)
1< and <=2 as medium (M)
2< as high (H)


OUTPUT:

out.dat
1.tmp 1.03 M
2.tmp 0.38 L
3.tmp 3.23 H
4.tmp 1.34 M

Could you please help??
Thanks
Po
# 2  
Old 07-05-2011
Code:
perl -e  'while(<>){chomp; @markers=qw(L M H);($val)=$_=~/([\d.]+$)/;$val=2 if $val > 2 ;print "$_ $markers[$val]\n"}' file1.dat

# 3  
Old 07-05-2011
Code:
awk '{$3=$2<1?"L":$2>2?"H":"M"}1' file1.dat

This User Gave Thanks to bartus11 For This Post:
# 4  
Old 07-05-2011
Meh Smilie

Last edited by Peasant; 07-05-2011 at 07:44 AM.. Reason: Bartus beat me with a shorter line :)
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Classify lines in file using perl

The below perl executes and does classify each of the 3 lines in file.txt. Lines 2 and 3 are correct as they fit the criteria for Rule 2. The problem is that line one should be classified VUS as it does not meet the criteria for Rule 1, so Rule 3 is used. However, currently Rule 2 is changing the... (27 Replies)
Discussion started by: cmccabe
27 Replies

2. Homework & Coursework Questions

IP Range Assigning

THIS IS A SAMPLE PRACTICAL EXAM QUESTION, COMPLETE FILE HAS BEEN ATTACHED AS WELL. Hi All, I'm a bit confused about assigning IP address from IP Ranges. I am using this scenario below to understand. Scenario Adatum.com an international IT solutions company, is launching 12 new branches in a... (10 Replies)
Discussion started by: TryllZ
10 Replies

3. IP Networking

IP Range Assigning

Hi All, I'm a bit confused about assigning IP address from IP Ranges. I am using this scenario below to understand. Scenario Adatum.com an international IT solutions company, is launching 12 new branches in a new country where they currently have no existing branches. The sWin CIO has asked... (3 Replies)
Discussion started by: TryllZ
3 Replies

4. Shell Programming and Scripting

Date range

Dear all, how can I select in the file below only the files created between Aug 14 2014 and Feb 03 2015? EZA2284I -rw-r--r-- 1 30 8 356954 Aug 15 2014 file1 EZA2284I -rw-rw-r-- 1 30 8 251396 Feb 05 12:53 file2 EZA2284I -rw-rw-r-- 1 30 8 ... (3 Replies)
Discussion started by: simomuc
3 Replies

5. Shell Programming and Scripting

AWK to classify a file into several ones ..

Good Day All, I need to make a script that will do the following : 1- read a .csv file line by line, check the 3 field of each file print the whole line if this field matches the condition (note : FS = ",") 2-from the basic file, the script should genrate 3 new files based on the step #1... (6 Replies)
Discussion started by: engkemo2002
6 Replies

6. Shell Programming and Scripting

How to use awk to classify file extension from input ls -l

i try to do this for a long time input is command ls -l and output is: Number of files : xx Number of file type – awk : 5 total size: 2345 bytes // file ex type .awk Number of file type – dat : 10 total size: 233 bytes // file ex type .dat ... Number of unknown file type... (1 Reply)
Discussion started by: retsuseiba
1 Replies

7. Shell Programming and Scripting

print range between two patterns if it contains a pattern within the range

I want to print between the range two patterns if a particular pattern is present in between the two patterns. I am new to Unix. Any help would be greatly appreciated. e.g. Pattern1 Bombay Calcutta Delhi Pattern2 Pattern1 Patna Madras Gwalior Delhi Pattern2 Pattern1... (2 Replies)
Discussion started by: joyan321
2 Replies

8. Shell Programming and Scripting

Range generator

Dear All, I have a sorted file like 1 2 3 8 9 10 45 46 47 78 The output will be range like 1 3 8 10 45 47 78 78 (9 Replies)
Discussion started by: saifurshaon
9 Replies

9. UNIX for Dummies Questions & Answers

Getting 'out of range' when partitioning

Hello, Using Solaris 10. Going to mirror disks with solstice disksuite. Documentation says I have to make both disks partitioned exactly the same before moving on. Here's the layout of c1t0d0 Part Tag Flag Cylinders Size Blocks 0 root wm 1237 - 2473 6.00GB (1237/0/0) 12587712 ... (1 Reply)
Discussion started by: pmichner
1 Replies
Login or Register to Ask a Question