[awk]: Row begins by random number and field 10 is greater than 10.00%


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [awk]: Row begins by random number and field 10 is greater than 10.00%
# 1  
Old 03-17-2005
[awk]: Row begins by random number and field 10 is greater than 10.00%

Hello!

I wish to extract the pid where CPU is above 10%
Code:
last pid: 22621;  load averages:  4.71,  5.04,  5.13                                                                                                15:08:34
221 processes: 212 sleeping, 2 running, 1 stopped, 6 on cpu
CPU states:     % idle,     % user,     % kernel,     % iowait,     % swap
Memory: 4096M real, 1810M free, 6148M swap free

  PID USERNAME THR PRI NICE  SIZE   RES STATE   TIME    CPU COMMAND
14990 oracle     1   0    0  401M  385M cpu14 316.5H 14.79% oracle
21104 oracle     1  58    0  401M  378M sleep   3:12  4.71% oracle
...

I tried like that
Code:
top | awk '/^[0-9][0-9]*/ && $10 >= "10.00%" {print $1}'

of course it doesn't work as awk is comparing alphabetically...

I wish to compare on value, I can get rid of % sign, I only don't remember how to tell to awk to compare the value not the string.

Thanks
# 2  
Old 03-17-2005
awk can translate string to float automatic.

try:
awk '($10 > 10)'
# 3  
Old 03-17-2005
Maybe use the int() function...
Code:
| awk '(int($1) == $1) && (int($10) > 10) {print $1}'

# 4  
Old 03-18-2005
Quote:
Originally Posted by ZealeS
awk can translate string to float automatic.

try:
awk '($10 > 10)'
yeah! it works fine, thanks! (I sed first to erase '%' signs)
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Find number begins with 24

Hi Team, i need to list only those number from the input file which begin with 24 input file is 2412 2413 2456 2134 2134 2244 2526 expected output i want is 2412 2413 2456 (6 Replies)
Discussion started by: scriptor
6 Replies

2. Shell Programming and Scripting

awk to skip header row and add string to field

The awk below does put in VUS in the 9th field but I can not seem to skip the header then add the VUS. I tried to incorporate NR >=2 and NR > 1 with no luck. Thank you :). input Chr Start End Ref Alt Func.refGene PopFreqMax CLINSIG Classification chr1 43395635 ... (5 Replies)
Discussion started by: cmccabe
5 Replies

3. Shell Programming and Scripting

At text to field 1 of header row using awk

I am just trying to insert the word "Index" using awk. The below is close but seems to add the word at the end and I can not get the syntax correct to add from the beginning. Thank you :). awk -F'\t' -v OFS='\t' '{ $-1=$-1 OFS "Index"}$1=$1' file current output Chr Start End ... (3 Replies)
Discussion started by: cmccabe
3 Replies

4. Shell Programming and Scripting

awk to find number in a field then print the line and the number

Hi I want to use awk to match where field 3 contains a number within string - then print the line and just the number as a new field. The source file is pipe delimited and looks something like 1|net|ABC Letr1|1530||| 1|net|EXP_1040 ABC|1121||| 1|net|EXP_TG1224|1122||| 1|net|R_North|1123|||... (5 Replies)
Discussion started by: Mudshark
5 Replies

5. Shell Programming and Scripting

awk transpose row into 2 field column

Need to transpose every 2 fields of a row into a single 2 field column. input 4 135 114 76 217 30 346 110 5 185 115 45 218 85 347 125 6 85 116 130 220 65 352 95 11 30 117 55 221 42 355 75 16 72 118 55 224 37 357 430 17 30 119 55 225 40 358 62 21 52 120 65 232 480 360 180 ....... (8 Replies)
Discussion started by: sdf
8 Replies

6. Shell Programming and Scripting

AWK: Cannot read Number of records greater than 1(NR>1)

Hi all, I have a tab-delimited text file of size 10Mb. I am trying to count the number of lines using, grep -c . sample.txtor wc -l < sample.txt or awk 'END {print NR}' sample.txtAll these commands shows the count as 1, which means they are reading only the first header line of the file.... (3 Replies)
Discussion started by: mehar
3 Replies

7. Shell Programming and Scripting

Printing entire field, if at least one row is matching by AWK

Dear all, I have been trying to print an entire field, if the first line of the field is matching. For example, my input looks something like this. aaa ddd zzz 123 987 126 24 0.650 985 354 9864 0.32 0.333 4324 000 I am looking for a pattern,... (5 Replies)
Discussion started by: Chulamakuri
5 Replies

8. Shell Programming and Scripting

Perl if field begins with.......

Hi, This must be simple but I can't get it to work. I have the follow code to insert the contents of a file into an array and then I want to print the value of a container where all of the records in another container within the array start with 33 (that's not all I want to do but it is all I... (2 Replies)
Discussion started by: Donkey25
2 Replies

9. Shell Programming and Scripting

AWK: row number NR

Hi I've file1 as: after I read all rows with awk, I need to change some of them. I mean, for example if the last row is zero then change row number 4 in zero too. So I'd like to refers each row as a vector and change its value accordly some conditions. I know that NR keep just the "current"... (2 Replies)
Discussion started by: Dedalus
2 Replies

10. Shell Programming and Scripting

doing rot13 on a field with a random number with awk

i have a several million line file like this: M:charitygeneral:water:fairbanks:charitygeneral field 2 and field 5 are the same i want to read the file and rot13 or any caesar cipher field 2 and replace the with a random number 1 - 9 anyone know how to do this? something slightly... (8 Replies)
Discussion started by: bathtub
8 Replies
Login or Register to Ask a Question