awk conditional find


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk conditional find
# 1  
Old 01-10-2013
awk conditional find

Hi,
I have a file in the following format:

Code:
 
aabbba 25.31806899
baaabb 38.21808852
cccccu  1.31819523
552258121.31818253
ffddybb 5.41815555
almcamc87561812689
223aqas5.661828345
adacaaaaaaa1821285
adacaaaaaaa1821286
smckaa  3.81828756
ada2512510c1821287
ada2522511c1821328
ada2532512c1821288
ada2542513c1821289
ada2552514c1821326
ada2562515c1821327
ada2572516c1821325
b234rds 5.61835663

I managed to extract last occurrence of a value, in this example 182 (column 12 to 14) using:

Code:
 
awk 'substr($0,12,3)==182 {line=$0} END{$0=line; print $0}' test.txt

which outputs

Code:
 
ada2572516c1821325

If possible I would like to find the row which corresponds to the maximum value in columns 16 to 19 and to 182, like:

Code:
 
smckaa  3.81828756

Any help will be greatly appreciated!
# 2  
Old 01-10-2013
Try:
Code:
awk '{v=substr($0,15,4)} substr($0,12,3)==182 && v>m{m=v; line=$0} END{print line}' infile


Last edited by Scrutinizer; 01-10-2013 at 09:14 AM.. Reason: changed 3 to 4 in the first substr
This User Gave Thanks to Scrutinizer For This Post:
# 3  
Old 01-10-2013
Thank you very much, worked perfect.
Best Regards
# 4  
Old 01-10-2013
You're welcome, I made 1 small modification, changing 3 to 4 in the first substr command..
# 5  
Old 01-10-2013
Thank you,
Best Regards
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Multi-conditional IF - awk

I have a 6 column array with 2 million rows that looks like this: 1 1089699 rs6686003 G A g 1 1090557 rs7553429 A C c 1 1094738 rs4970362 A G a 1 1099342 rs9660710 A C c 1 1106473 rs4970420 G A a 1 1108637 rs4970421 G A g 1 1119858 rs1320565 C T c 1... (5 Replies)
Discussion started by: Geneanalyst
5 Replies

2. UNIX for Beginners Questions & Answers

Conditional Arithmetic in [g]awk

I am having a difficult time getting an awk one-liner to work correctly that runs a mathematical operation upon values in a field when matching a given criteria. I would like to subtract 1 from every value in field $6 that is greater than 12. In this particular case it is only a constant of... (3 Replies)
Discussion started by: jvoot
3 Replies

3. Shell Programming and Scripting

[awk] conditional printing

Heya I'm trying to get to know awk a bit better. So i'm trying to get used to calls saving me a grep invocation just to get a specific part of a single line. This said, i want to get the current screen resolution according to xrandr's output. Screen 0: minimum 8 x 8, current 1920 x 1080,... (1 Reply)
Discussion started by: sea
1 Replies

4. Shell Programming and Scripting

awk conditional output

Hello, How can I use a conditional to produce an output file that varies with respect to the contents of column #4 in the data file: Data file: 9780020080954 9.95 0.49 AS 23.3729 9780020130857 9.95 0.49 AS 23.3729 9780023001406 22.20 0.25 AOD ... (12 Replies)
Discussion started by: palex
12 Replies

5. Shell Programming and Scripting

Conditional awk

Hello All, I have a file like this: bash-3.00$ cat 1.txt 201112091147|0|1359331220|1025 201112091147|0|1359331088|1024 201112091144|0|1359331172|1025 201112091147|0|1359331220|1021 201112091149|0|1359331088|1027 201112091144|0|1359331172|1029 and a list of MSISDNs in another file... (9 Replies)
Discussion started by: EAGL€
9 Replies

6. Shell Programming and Scripting

AWK conditional addition

I have a column of numbers $2, I would like to add 360 to all numbers that are negative. This method seems a bit convoluted, and does not work (outputs 0): BEGIN { A=sprintf("%d", $2); if(A<0) A=A+360; BIN++; } END { for(A in BIN) print... (5 Replies)
Discussion started by: chrisjorg
5 Replies

7. Shell Programming and Scripting

awk help to do conditional find and replace

Hi, I have a Line input for awk as follows DROP MATERIALIZED VIEW MCR.COMM_STACK; CREATE MATERIALIZED VIEW "MCR"."COMM_STACK" ON PREBUILT TABLE WITHOUT REDUCED PRECISION USING INDEX REFRESH FAST ON DEMAND START WITH sysdate+0 NEXT SYSDATE + 7 WITH PRIMARY KEY USING DEFAULT... (3 Replies)
Discussion started by: rajan_san
3 Replies

8. Shell Programming and Scripting

Awk Conditional

Hi Guys, i have this files: xyz20080716.log opqrs20080716.log abcdef20080716.log xyz20080717.log oprs20080717.log abcde20080717.log currentdate: 20080717.log I want to make script to zip the file for past day. Can anyone help for this? i've just learn awk scripting & still confused with... (3 Replies)
Discussion started by: icy_blu_blu
3 Replies

9. Shell Programming and Scripting

AWK - conditional cause

Hello guys, I want to make a conditional cause in the following file using awk: awk '{ if ($2 != 0) print $1, $2, $3}' test.csv > test2.csv FILE EXAMPLE = test.csv string,number,date abc,0,20050101 def,1,20060101 ghi,2,20040101 jkl,12,20090101 mno,123,20020101 ... (2 Replies)
Discussion started by: Rafael.Buria
2 Replies

10. Shell Programming and Scripting

awk conditional statement

how can i use awk or sed to do a conditional statement, so that HH:MM if MM not great than 30 , then MM=00 else MM=30 ie: 10:34 will display 10:30 10:29 will display 10:00 a=$(echo 10:34 | awk ......) Thanks in advance (10 Replies)
Discussion started by: 3Gmobile
10 Replies
Login or Register to Ask a Question