filtering a numeric value which has '%' using awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting filtering a numeric value which has '%' using awk
# 1  
Old 03-12-2012
filtering a numeric value which has '%' using awk

Hello Gurus,

I have a requirement where I have to filter a value from some field which has 99% or greater than '99%'..
For ex:
The Date (file -- sample.csv) will be like below
Code:
Field1,Field2,Field3,Field4
860440512,844284992,16155520,99%
860440512,844284992,16155520,94%
860440512,844284992,16155520,100%
860440512,844284992,16155520,99%
860440512,844284992,16155520,98%

Now I have to extract the values which has >= 99%... I have tried the below way...

Code:
 
cat sample.csv | awk -F',' '{if ( $3 < 5242880 || $4 >= "99%" ) print $1,$2,$3,$4}'

but as this is containing special charecter and numaric values, it is unable to satisfy the given numaric operator (>=)

Could anyone suggest me the way here pls?

Thanks in advance.

Regards,
VRN

Last edited by radoulov; 03-12-2012 at 04:39 PM.. Reason: Additional code tags.
# 2  
Old 03-12-2012
hard to see your sample file....
Code:
awk -F',' '{if ( $3 < 5242880 || int($4) >= 99 ) print $1,$2,$3,$4}' sample.csv

# 3  
Old 03-12-2012
Code:
 
bash-2.03$ cat sample.csv
Field1,Field2,Field3,Field4
860440512,844284992,16155520,99%
860440512,844284992,16155520,94%
860440512,844284992,16155520,100%
860440512,844284992,16155520,99%
860440512,844284992,16155520,98%
bash-2.03$ awk -F',' '{if ( int($4) >= 99 ) print $1,$2,$3,$4}' sample.csv
bash-2.03$

Seems it is not working... could you pls have a look at the above and suggest?
# 4  
Old 03-12-2012
What OS are you using. If on Solaris try /usr/xpg4/bin/awk instead of awk

Last edited by Scrutinizer; 03-12-2012 at 05:03 PM..
# 5  
Old 03-12-2012
thanks much for the suggestion... It worked.... Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Filtering text with awk

I need to filter a file that is composed like that: >Cluster 0 0 292nt, >last294258;size=1;... * >Cluster 1 0 292nt, >last111510;size=1;... * 1 290nt, >last136280;size=1;... at -/98.62% 2 292nt, >last217336;size=1;... at +/99.66% 3 292nt, >last280937;size=1;... at -/99.32% >Cluster 2... (6 Replies)
Discussion started by: pedro88
6 Replies

2. Shell Programming and Scripting

Variable filtering in awk

Hello all, can you explain why this filter does not work, it prints all the lines in the file: awk -v sel="TestString" 'sel' file while these work: awk '/TestString/' file awk -v sel="TestString" '$0~sel' file Thanks!:) (6 Replies)
Discussion started by: gio001
6 Replies

3. Shell Programming and Scripting

awk using sub , filtering textfile

i have text file as below CMF_COMP_ELEM_ GSM2_B71.WORLD_20121114130908.log 107496444 rows inserted into ALL_S1_CMF_COMP_ELEM. CMF_COMP_ELEM_ GSM3_B71.WORLD_20121114130908.log 110729006 rows inserted into ALL_S1_CMF_COMP_ELEM. CMF_COMP_ELEM_ GSM4_B71.WORLD_20121114130908.log 92549475... (8 Replies)
Discussion started by: only4satish
8 Replies

4. Shell Programming and Scripting

awk data filtering

I am trying to filter out some data with awk. If someone could help me that would be great. Below is my input file. Date: 10-JUN-12 12:00:00 B 0: 00 00 00 00 10 00 16 28 B 120: 00 00 00 39 53 32 86 29 Date: 10-JUN-12 12:00:10 B 0: 00 00 00 00 10 01 11 22 B 120: 00 00 00 29 23 32 16 29... (5 Replies)
Discussion started by: thibodc
5 Replies

5. Shell Programming and Scripting

filtering awk not using grep

hallow all i have question about awk i want indexing last key (in BOLD number) ex: input.txt 1 252468812 52468812 1281268819 1252468812 1252468923 468812 1252468812 so output will like this output text 1:252468812 2:52468812 4:1252468812 6:468812 7:1252468812 output get... (8 Replies)
Discussion started by: zvtral
8 Replies

6. Shell Programming and Scripting

filtering with awk

i have question about awk ex: input.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 1252468819,yahoo,1.2 msn,1252468812,8.9 1252468923,gmail,12 live,1252468812,3.4 yahoo,1252468812,9.0 1252468929,msn,1.2 output.txt 1252468812,yahoo,3.5 1252468812,hotmail,2.4 msn,1252468812,8.9... (3 Replies)
Discussion started by: zvtral
3 Replies

7. Shell Programming and Scripting

Filtering out text with awk

(0 Replies)
Discussion started by: nilekyle
0 Replies

8. Shell Programming and Scripting

awk filtering, then execution

Hi, I need to do the following but I don't know exactly what to do. I need to monitor a file ... with tail -f for example, but I know that I could do it with awk, wait for a specific string ... , then perform an action, call a script, etc. Let's say that my file name is test.txt , I need... (3 Replies)
Discussion started by: ocramas
3 Replies

9. Shell Programming and Scripting

filtering records based on numeric field value in 8th position

I have a ";" delimited file.Whcih conatins a number fileds of length 4 charcters in 8th position But there is a alphanumeric charcters like : space, ";" , "," , "/" , "23-1" , "23 1" , "aqjhdj" , "jun-23" , "APR-04" , "4:00AM" , "-234" , "56784 ", "." , "+" "_" , "&" , "*" , "^" , "%" , "!"... (2 Replies)
Discussion started by: indusri
2 Replies

10. UNIX for Advanced & Expert Users

awk filtering ?

I have a Ques. Regarding awk I have few strings in a file, like.. ABC DEF_ABC GHI_ABC GHI Now I want string which has only 'ABC', not the part of any other string as it is also present in 'DEF_ABC' Output should be ABC Please guide me asap !! Thanks :b: (4 Replies)
Discussion started by: varungupta
4 Replies
Login or Register to Ask a Question