Help me to find a greater than or smaller than values


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help me to find a greater than or smaller than values
# 1  
Old 10-17-2013
Help me to find a greater than or smaller than values

Hi,

i need to find one of the value from my file is in between two numbers, that is the value is greater than 34 and smaller than 50,

Ex: File.txt
Code:
col1	col2	col3	col4
1	Name1	93	w
2	Name2	94	a
3	Name3	32	b
4	Name4	45	x
5	Name5	50	y
6	Name6	49	z

here i need to find col3 values are greater than 34 and smaller than 50 then i have to replace it with 29.

outputFile.txt
Code:
col1	col2	col3	col4
1	Name1	93	w
2	Name2	94	a
3	Name3	32	b
4	Name4	29	x
5	Name5	50	y
6	Name6	29	z

please help me!
# 2  
Old 10-17-2013
Code:
$ awk '(($3 > 34) && ($3 < 50)) {$3=29} 1' OFS='\t' file
col1    col2    col3    col4
1       Name1   93      w
2       Name2   94      a
3       Name3   32      b
4       Name4   29      x
5       Name5   50      y
6       Name6   29      z

# 3  
Old 10-17-2013
Try

Code:
$ awk '$3>34 && $3<50{$3=29}1' OFS=\\t file

Resulting
Code:
col1   col2    col3   col4
1    Name1    93    w
2    Name2    94    a
3    Name3    32    b
4    Name4    29    x
5    Name5    50    y
6    Name6    29    z

# 4  
Old 10-17-2013
Perl
Code:
Code:
perl -F"\s" -lane 'if($F[2] gt 34 && $F[2] lt 50) { $F[2]=29;} print "@F";'  filename

# 5  
Old 10-17-2013
will this work for floating point also?

and if i want to add one more condition like col5 has < 79 then it have 0 values. and i need to print in separate col. like

input file.txt

Code:
col1	col2	col3	col4	col5	col6
1	Name1	93	w	46	n/a
2	Name2	94	a	59	n/a
3	Name3	32	b	70	n/a
4	Name4	75	x	20	n/a
5	Name5	50	y	19	n/a
6	Name6	49	z	40	n/a

and outputfile.txt
Code:
col1	col2	col3	col4	col5	col6
1	Name1	93	w	46	n/a
2	Name2	94	a	59	n/a
3	Name3	36	b	83	29
4	Name4	40	x	20	0
5	Name5	45	y	19	0
6	Name6	49	z	80	29

# 6  
Old 10-17-2013
Floating point should be fine.

In your new example quite a lot of the values have changed, not just column 5?
# 7  
Old 10-17-2013
Like this ?
Code:
awk '$3>34 && $3<50 { $3=29;if ($5<79) $6=0}1' OFS=\\t

Please modify the conditions as per your need to get desired output.

Last edited by greet_sed; 10-17-2013 at 08:41 AM.. Reason: OP expected output and explantion differs
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to replace the field values, which are greater than the specified value with TRUE?

I have a csv file as given below, org1 org2 org3 org4 org5 gene1 100 80 90 80 150 gene2 30 70 50 50 115 gene3 40 120 60 40 105 gene4 20 72 40 60 20 I need to replace the fields are having values greater than 100 with "TRUE". I used the following commands to replace... (6 Replies)
Discussion started by: dineshkumarsrk
6 Replies

2. Shell Programming and Scripting

How to print values that are greater than 0.1 in at least 80% of the samples?

input sample1 sample2 sample3 sample4 sample5 sample6 sample7 sample8 sample9 sample10 v1 0.2 0.1 0.1 0 1 2 3 4 9 10 v2 0 0 0.01 0 0 0 0 0 0 0 v3 0 0 0 0 0 ... (35 Replies)
Discussion started by: quincyjones
35 Replies

3. Shell Programming and Scripting

Find and substitute if greater than.

I have large config-files for an application. The lines have different structure, but some of them contains the parameter 'TIMEOUT=x', where x is an numeric value. I want to change the value for that specific paramater if the value is greater than a specific value (got that?). The timeout-parameter... (3 Replies)
Discussion started by: useless
3 Replies

4. Shell Programming and Scripting

awk to get values greater than

data.txt August 09 17:16 2013 August 09 17:17 2013 August 09 17:19 2013 August 09 17:20 2013 August 09 17:21 2013 August 09 17:22 2013 August 09 17:23 2013 August 09 17:24 2013 to print from a point in this file, to the end of the file, i type: awk '/August 09 17:22/,0' data.txt. ... (1 Reply)
Discussion started by: SkySmart
1 Replies

5. Shell Programming and Scripting

find greater than value

Hi I want to find greater than and min value. dategrep() { varlinenum=$1 varSESSTRANS_CL="$(egrep -n "<\/SESSTRANSFORMATIONINST>" tmpsess9580.txt | cut -d":" -f1)" echo $varSESSTRANS_CL } dategrep 8 Output of the above command is: I want to find out greater than 8 and... (9 Replies)
Discussion started by: tmalik79
9 Replies

6. Shell Programming and Scripting

Find image greater than x pixels?

Hi Guys, I have a little problem, was wondering if anyone had any experience with this? I am using imagemagick to remove whitespace from images, however some images are corrupt and the server hangs and eventually crashes because imagemagick doesnt know what to do, even though I have set the... (4 Replies)
Discussion started by: mikemeadeuk
4 Replies

7. Shell Programming and Scripting

Trying to find files equal to and greater than

Hi Guys and Gals, I'm having some difficulty putting this check into a shell script. I would like to search a particular directory for a number of files. The logic I have is pretty simple: Find file named *.txt that are newer than <this file> and count them If the number of files is equal to... (4 Replies)
Discussion started by: bbbngowc
4 Replies

8. Shell Programming and Scripting

Lookup two values per line (from a second file) and write the smaller value to another file

Hello Unix Gurus, Please let me know if this is hard to understand and I apologize for my inability to explain better. I have a file "Foo" with the following structure CHR_A BP_A SNP_A CHR_B BP_B SNP_B R2 1 ... (3 Replies)
Discussion started by: genehunter
3 Replies

9. Shell Programming and Scripting

Finding absolute values greater than a certain value

Hi I am posting here for the first time. I am trying to write a script that reads a data file and tries to determine if any absolute values that are above 0.5 I was thinking it ought to be possible to do this with awk somehow. Are there any suggestions before I start reinventing the wheel? ... (4 Replies)
Discussion started by: jackygrahamez
4 Replies

10. Shell Programming and Scripting

find port greater than 6000

How to get the listening ports which is greater than 6000 using netstat ? (1 Reply)
Discussion started by: gsiva
1 Replies
Login or Register to Ask a Question