How to print only number using awk command in Linux ?

 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers How to print only number using awk command in Linux ?
# 1  
Old 05-13-2017
How to print only number using awk command in Linux ?

Now I'm trying summary sar data.

CPU , Memory , Traffic , TPS (Min Max value)

CPU is okay using below command.
Code:
[Server]$  sar -p | awk '{gsub(/[^0-9. ]/,"")}1' | awk 'BEGIN {min=1000000; max=0;};\
 { if($7<min && $7 != "") min = $7; if($7>max && $7 != "") max = $7; } END {print min, max}'
98.93 99.55

but other things.....It doesn't work....

Please teach me why it doesn't work for another value.

Last edited by vbe; 05-13-2017 at 06:11 AM.. Reason: code tags
# 2  
Old 05-13-2017
Can you explain what does not work?
Please give us a line or two of data and the "wrong" output, then tell us what it should be.

Your code looks like it is finding the maximum and minimum values for a given field. I would suspect the data is not completely consistent.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk - Print column number that return value comes from

I have the following awk script that I am using to find the max value in the file and print results. awk 'BEGIN {MAX=-1E100} {for (x=2; x<=NF; x++) if ($x>MAX) {MAX = $x; C1 = $1}} END {print substr(C1,1,11), substr(C1,13,4), substr(C1,18,2), MAX}' ABC* Input (ABC*) ... (6 Replies)
Discussion started by: ncwxpanther
6 Replies

2. Shell Programming and Scripting

Print Unknown Number of User Inputs in awk

Hello, I am new to awk and I am trying to figure out how to print an output based on user input. For example: ubuntu:~/scripts$ steps="step1, step2, step3" ubuntu:~/scripts$ echo $steps step1, step2, step3 I am playing around and I got this pattern that I want: ... (3 Replies)
Discussion started by: tattoostreet
3 Replies

3. 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

4. Shell Programming and Scripting

AWK print number of records, divide this number

I would like to print the number of records of 2 files, and divide the two numbers awk '{print NR}' file1 > output1 awk '{print NR}' file2 > output2 paste output1 output2 > output awl '{print $1/$2}' output > output_2 is there a faster way? (8 Replies)
Discussion started by: programmerc
8 Replies

5. Shell Programming and Scripting

print max number of 2 columns - awk

Is it possible to print max number of 2 columns - awk note: print max if the integer is positive and print min if the integer is negative input a 1 2 b 3 4 c 5 1 d -3 -5 d -5 -3 output a 2 b 4 c 5 d -5 d -5 (4 Replies)
Discussion started by: quincyjones
4 Replies

6. Shell Programming and Scripting

awk: print columns depending on their number

hi guys, i have the following problem: i have a matrix with 3 columns and over 450 rows like this: 0.0165 0.0151 0.0230 0.0143 0.0153 0.0134 0.0135 0.0123 0.0195 0.0173 0.0153 0.0182 i now want to calculate the average of every line and divide every element of this... (1 Reply)
Discussion started by: waddle
1 Replies

7. Shell Programming and Scripting

Please help. How to print number with 'awk'?

Dear all, I have to transform a bunch of files into a new format. how to do it with bash script, especially with 'awk' command. the original data O,0,0.2839896442,-1.1628392411,-1.5976515479 Cr,0,-0.0502858628,-0.1725974837,-0.380627632 C,0,2.4506658279,-0.476964918,0.2299298249 ... (3 Replies)
Discussion started by: liuzhencc
3 Replies

8. Shell Programming and Scripting

How do I print out lines with the same number in front using awk?

Hi, I need help in printing out the dates with the largest value in front of it using awk. 436 28/Feb/2008 436 27/Feb/2008 436 20/Feb/2008 422 13/Feb/2008 420 23/Feb/2008 409 21/Feb/2008 402 26/Feb/2008 381 22/Feb/2008 374 24/Feb/2008 360... (7 Replies)
Discussion started by: SIFA
7 Replies

9. Shell Programming and Scripting

awk to print exact field number

Hello there. I want some help with awk I have this script that reads a file from awk and you can insert from keyboard any list from the fields that exist so to be printed on monitor echo "give a choice" read -a ans array=${ans} awk -F: -v k="$array" '{ ... (4 Replies)
Discussion started by: covis
4 Replies

10. Shell Programming and Scripting

How to print number of lines with awk ?

Can some body tell me how to print number of line from a particular file, with sed. ? Input file format AAAA BBBB CCCC SDFFF DDDD DDDD Command to print line 2 and 3 ? BBBB CCCC And also please tell me how to assign column sum to variable. I user the following command it... (1 Reply)
Discussion started by: maheshsri
1 Replies
Login or Register to Ask a Question