Checking for higher usage and mark it


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Checking for higher usage and mark it
# 8  
Old 07-01-2010
In fact I'd like to use int() in awk.

Code:
awk '{(int($NF)>80)?$0=$0 " Warning":X}1' urfile

# 9  
Old 07-01-2010
Hi Gurus,

For my understanding, would anybody be able to help to explain what does this code mean and what does it do ?

Why need to use “awk” in this format? And what is the use of “split” ?

Code:
awk '/\// {split($NF,a,"%"); if (a[1]>80) $0=$0 "  Warning";}1' file

Please kindly advice.

Thanks.


Regards,
Peter

---------- Post updated at 05:38 AM ---------- Previous update was at 01:57 AM ----------

Hi rdcwayx,

Thank you for your help.

Had tested your method and it's working as expected.

Code:
awk '{(int($NF)>80)?$0=$0 " Warning":X}1' urfile

Are you able to share a little what does the above command mean? What is "$0=$0" ?

Please kindly advice.

Thanks.



Regards,
Peter
# 10  
Old 07-01-2010
?: is a ternary operator. AWK Language Programming - Expressions
# 11  
Old 07-01-2010
Peter..

Let's take an example:

Code:
     x>20?y=10:y=15
     x>20?y=20:1

First one says, If x>20, set 10 to y, else set 15 to y.
Now, say you dont want to do anything in the else condition, check the second example now: since we dont want to do anything, we simply put something(1 in this case) in the else clause to satisfy the syntax.

In the same lines,
Code:
(int($NF)>80)?$0=$0 " Warning":X

if your value is > 80, append warning to the line($0=$0 " Warning"), else to satisfy the syntax, something(X here).

Hope its clear now.

Guru.
# 12  
Old 07-02-2010
Hi guruprasadpr,

Got it. Thank you for your kind explanation.


Regards,
Peter
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. OS X (Apple)

A simple plaything for a 19 month old and higher.

This thread today reminded me of it: https://www.unix.com/shell-programming-and-scripting/279465-larger-window.html#post303021017 This is OSX 10.13.6 and greater centric only. This expands the terminal window on the fly in bash. You initially need to put the standard terminal window to the top... (0 Replies)
Discussion started by: wisecracker
0 Replies

2. UNIX for Dummies Questions & Answers

Remove when date is higher

Dear Masters, I need to eliminate lines from file input 2 when the date in column 1 more than date in column 1 in file input 1 input 1 20141101|USA|CANSEL|496420000 20141101|USA|CANUT|1069740000 20141101|USA|CANTENG|625920000 20141102|USA|CANUT|413180000 20141103|USA|CANSEL|1364245000... (5 Replies)
Discussion started by: radius
5 Replies

3. What is on Your Mind?

Where to find higher consulting rates?

Have any IT consultants here been on a project where you knew the bill rate was really high but you only got a tiny piece of it (like paid $60/hr and billed out around $200)? Does anyone know of a company that pays consultants well - like 70-80% or more of what they're getting? (5 Replies)
Discussion started by: apierce
5 Replies

4. UNIX for Dummies Questions & Answers

grep 2000 and higher

i have content that looks like this: 0003326050 A E LITHO 0023823422 AMERICAN RED CROSS 0005713642 ARUP LABORATORIES 0003206450 CAEL 0002519930 CARDINAL HEALTH 0002619063 FISHER HEALTHCAR 0065203177 OWENS & MINOR INC 0016552938 STAPLES INC 0000002001 MSC... (8 Replies)
Discussion started by: tjmannonline
8 Replies

5. AIX

How to monitor the IBM AIX server for I/O usage,memory usage,CPU usage,network..?

How to monitor the IBM AIX server for I/O usage, memory usage, CPU usage, network usage, storage usage? (3 Replies)
Discussion started by: laknar
3 Replies

6. UNIX for Advanced & Expert Users

Checking mem usage at specific times in a program

Hi all, I'm running a simulator and I'm noticing an slow increase in memory for long simulations such that the simulation has to end because of a lack of memory. A colleague of mine ran Valgrind memcheck and reported that nothing of interest was reported other than known mem leaks. My advisor... (2 Replies)
Discussion started by: pl4u
2 Replies

7. HP-UX

how can I find cpu usage memory usage swap usage and logical volume usage

how can I find cpu usage memory usage swap usage and I want to know CPU usage above X% and contiue Y times and memory usage above X % and contiue Y times my final destination is monitor process logical volume usage above X % and number of Logical voluage above can I not to... (3 Replies)
Discussion started by: alert0919
3 Replies

8. UNIX for Dummies Questions & Answers

Checking CPU Usage and available free physical and virtual memories

Hi , can anyone please guide me on how do i go about getting the CPU Usage and available free physical and virtual memories? i know i can get it by using prstat, but i want to get an overall CPU Usage and not a breakdown of all same for the free physical and virtual memories ? (2 Replies)
Discussion started by: filthymonk
2 Replies

9. UNIX for Advanced & Expert Users

Backgrounding process with higher priority

I have been troubleshooting a mysterious performance problem with the nightly batch programs on our primary system for quite some time and just found something very interesting. All batch processes are running with a nice value of 24. I don't know what the default is on other systems but I do know... (3 Replies)
Discussion started by: keelba
3 Replies
Login or Register to Ask a Question