awk if percent % checking


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting awk if percent % checking
# 1  
Old 05-17-2010
awk if percent % checking

hi everyone,
Code:
[root@]# cat a
a 10%
b 25.5%
c 91%
d 50%

[root@]# cat a | awk '$2 >= 90%; END {print $_}'
awk: $2 > 90%; END {print $_}
awk:         ^ syntax error
awk: each rule must have a pattern or an action part

how to do only print when 2nd coln >= 90%.
Thanks
# 2  
Old 05-17-2010
Code:
awk '$2 >= 90 {print $1}' a

Use nawk with Solaris.
# 3  
Old 05-17-2010
try..
Code:
awk 'int($2) > 90 ' file_name


Last edited by posix; 05-17-2010 at 04:40 AM.. Reason: tag.
# 4  
Old 05-17-2010
Quote:
Originally Posted by jlliagre
Code:
awk '$2 >= 90 {print $1}' a

Use nawk with Solaris.
Thanks, but your output is wrong, the output just "c".
posix is correct.

---------- Post updated at 02:54 AM ---------- Previous update was at 02:50 AM ----------

Quote:
Originally Posted by posix
try..
Code:
awk 'int($2) > 90 ' file_name

Thanks, i have another question:
how do i combine "awk 'int($2) > 90 ' a", with "sub {/c/, d}", and "sub {/ /, /\t/}"
means from the output of "c 90%", to "d 90%".

Please advice.
Thanks
# 5  
Old 05-17-2010
Quote:
Originally Posted by jimmy_y
Thanks, but your output is wrong, the output just "c".
The ouput is not wrong, not just the one you were expecting. "c" is the only value with which column 2 is > 90%. I though you wanted to display only the first column as you didn't tell anything about the expected result and there was a print statement in your code.
Quote:
posix is correct.

Indeed although int() is unecessary, awk is already doing this by default.
Code:
awk '$2 >= 90' a

# 6  
Old 05-17-2010
Code:
awk '{if ( $2 >= 90 ) print $1," " $2 }' filename

# 7  
Old 05-17-2010
Quote:
Thanks, i have another question:
how do i combine "awk 'int($2) > 90 ' a", with "sub {/c/, d}", and "sub {/ /, /\t/}"
means from the output of "c 90%", to "d 90%".

Please advice.
Thanks
Code:
awk '$2 >= 90{gsub("c","d",$1);print}' infile

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to calculate total and percent off field in file

Trying to use awk to print the lines in file that have either REF or SNV in $3, add a header line, sort by $4 in numerical order. The below code does that already, but where I am stuck is on the last part where the total lines are counted and printed under Total_Targets, under Targets_less_than is... (4 Replies)
Discussion started by: cmccabe
4 Replies

2. Shell Programming and Scripting

awk - checking last three characters

Hello, I am working with some very large files (upwards of 1M records). I have written code to parse out a lot of the data and am using awk rather than a built-in "while read LINE" for performance (I have tested both ways). That said, I now need to read each of these incoming lines, check the ninth... (2 Replies)
Discussion started by: dagamier
2 Replies

3. Shell Programming and Scripting

Checking existence of file using awk

Hi, I need to check whether a particular file exists ot not using awk. Can anyone help me please? For Example:script that i am using: awk '{filename =$NF; rc=(system("test -r filename")) print $rc;}' "$1" is not working. Here I am passing a text file as input whose last word contains a... (6 Replies)
Discussion started by: manish007
6 Replies

4. Shell Programming and Scripting

Checking conditions with AWK

Input File1 0BB2 2A11 Split,FriApr80625,1507_7RAID5 0BF6 2829 Synchronized,FriJan140653,1507_7RAID5 0BF6 282A Split,FriApr80625,1507_7RAID5 0C7C 199E Synchronized,FriJan140653,1507_7RAID5 0C7C 1BCC Split,FriApr80625,1507_7RAID5 0DCA 0A9B ... (12 Replies)
Discussion started by: greycells
12 Replies

5. Shell Programming and Scripting

Checking a file using awk

I have a file that looks like this, with the first number in each block within each SOURCE declaration being a distance. %( PHASES P %) %( SOURCES (10,0.0) (13,0.0) (16,0.0) (19,0.0) (22,0.0) (25,0.0) (28,0.0) (31,0.0) (34,0.0) (37,0.0) (0 Replies)
Discussion started by: kristinu
0 Replies

6. Shell Programming and Scripting

Awk and checking options

My task is that when the user calls the script 1. If user calls script with awk -v dtmax= -v stdlim= -f ../Scripts/add-rgauss-xt.awk fin.xt > fout.xt rgauss will return mean + (stdlim * sigma) 2. If user calls script with awk -v dtmax= -f ../Scripts/add-rgauss-xt.awk fin.xt > fout.xt... (4 Replies)
Discussion started by: kristinu
4 Replies

7. Shell Programming and Scripting

Checking the length using awk??

I have following data in a file a.txt HELLO123456789 HELLO098765432 HELLO322366565 HELLO2343435 HELLO45343 I have to filter those lines whose length is not equal to 14 using awk. Thanks in advance:b: (1 Reply)
Discussion started by: nohup
1 Replies

8. UNIX for Dummies Questions & Answers

what the %s does percent sign-s mean?

context: while reading tutorial on the read command, one of the first examples, demonstrating its use, follows as such: $ x=abc ; printf "x is now '%s'. Enter new value: " $x ; read x generating this output: x is now 'abc'. Enter new value: first, what does %s represent? I know... (3 Replies)
Discussion started by: ProGrammar
3 Replies

9. Shell Programming and Scripting

Find percent between sum of 2 columns awk help

Hi I'm new to this forum and I'm a beginner when it comes to shell and awk programming. But I have the following problem: I have 5 csv files (data1.csv, data2.csv, etc.) and need to calculate the average between the total sum of the 1st and 7 column. csv example:... (3 Replies)
Discussion started by: sapo51
3 Replies

10. Shell Programming and Scripting

Awk type checking

Hello, How to check if two variables( fields in awk) have the same datatype ( INTEGER , REAL, TEXT ) ? (2 Replies)
Discussion started by: scotty_123
2 Replies
Login or Register to Ask a Question