Get value of last row and 6 column from awk


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Get value of last row and 6 column from awk
# 1  
Old 07-08-2008
Get value of last row and 6 column from awk

I want to get value of last row and 6 column from awk. Below is the format of my file. And RED one is my desired value. Actaully this stats usally update after every 1 hour so i want that every time i run the script i get the latest value.

Ending time - 01:00:58
HOURLY CALL ATTEMPTS (NORMALIZED) = 58227
Ending time - 02:00:59
HOURLY CALL ATTEMPTS (NORMALIZED) = 39987
Ending time - 03:00:58
HOURLY CALL ATTEMPTS (NORMALIZED) = 20922
Ending time - 04:00:56
HOURLY CALL ATTEMPTS (NORMALIZED) = 11385
Ending time - 05:00:57
HOURLY CALL ATTEMPTS (NORMALIZED) = 6441
Ending time - 06:00:56
HOURLY CALL ATTEMPTS (NORMALIZED) = 6598
Ending time - 07:00:59
HOURLY CALL ATTEMPTS (NORMALIZED) = 14472
Ending time - 08:00:59
HOURLY CALL ATTEMPTS (NORMALIZED) = 30849
Ending time - 09:00:58
HOURLY CALL ATTEMPTS (NORMALIZED) = 59088
Ending time - 10:00:58
HOURLY CALL ATTEMPTS (NORMALIZED) = 99476

When i use this command
Code:
more filename | awk '{print $6 }'

so it gives me the 6th column of all file but what i exactly want is last line and 6th column.

I hope, you understand.

lease HELP....

Regards,
Waqas Ahmed

Last edited by wakhan; 07-08-2008 at 12:59 PM..
# 2  
Old 07-08-2008
Code:
tail -1 filename | awk '{print $6}'

# 3  
Old 07-08-2008
Code:
awk -F'= ' 'END{print $NF}' file

Use /usr/xpg4/bin/awk on Solaris.

With nawk:

Code:
nawk -F'= ' '{_=$NF}END{print _}' file

Or:

Code:
sed -n '$s/.*= //p' file

If the leading space is not a problem:

Code:
tail -1 file|cut -d= -f2


Last edited by radoulov; 07-08-2008 at 06:07 PM..
# 4  
Old 09-05-2008
What if...???

...I want to capture the value of the third row, sixth column.
How do I do that in awk?

HOURLY CALL ATTEMPTS (NORMALIZED) = 20922

Thanks
# 5  
Old 09-05-2008
Quote:
Originally Posted by amontene
...I want to capture the value of the third row, sixth column.
How do I do that in awk?

HOURLY CALL ATTEMPTS (NORMALIZED) = 20922

Thanks
Try the below one:

Quote:
/home/ans >var=3
/home/ans >awk -v val=$var ' { if (NR==2*val) print $NF }' filename
20922
/home/ans >var=4
/home/ans >awk -v val=$var ' { if (NR==2*val) print $NF }' filename
11385
If you need the complete row, replace print $NF with print
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Script to do column to row in awk

Hi , Can anyone help me suggesting - how to do the below trick with awk Input 120 130 140 210 310 410 645 729 800 Output 120 130 140 (6 Replies)
Discussion started by: Indra2011
6 Replies

2. Shell Programming and Scripting

awk script row to column

Hi.. I have data : Report testing1 20180419 08:00 Report testing2 20180419 07:35 Report testing 20180419 08:01 Source = data1 Report testing4 20180419 08:05 Source = data1 Report testing5 20180419 08:10 Source = data2 Report testing6 20180419 08:01 Report testing7 20180419 08:19... (4 Replies)
Discussion started by: buncit8
4 Replies

3. Shell Programming and Scripting

Transpose column to row - awk

Hi there, I have a small csv file example below: source,cu_001,cu_001_volume,cu_001_mass,cu_002,cu_002_volume,cu_002_mass,cu_003,cu_003_volume,cu_003_mass ja116,1.33,3024000,9374400,1.54,3026200,9375123,1.98,3028000,9385512 I want to transpose columns to rows starting at the second... (3 Replies)
Discussion started by: theflamingmoe
3 Replies

4. UNIX for Dummies Questions & Answers

awk to print first row with forth column and last row with fifth column in each file

file with this content awk 'NR==1 {print $4} && NR==2 {print $5}' file The error is shown with syntax error; what can be done (4 Replies)
Discussion started by: cdfd123
4 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

Subtracting each row from the first row in a single column file using awk

Hi Friends, I have a single column data like below. 1 2 3 4 5 I need the output like below. 0 1 2 3 4 where each row (including first row) subtracting from first row and the result should print below like the way shown in output file. Thanks Sid (11 Replies)
Discussion started by: ks_reddy
11 Replies

7. UNIX for Dummies Questions & Answers

awk: convert column to row in a specific way

Hi all! I have this kind of output: a1|b1|c1|d1|e1 a2|b2|c2 a3|b3|c3|d3 I would like to transpose columns d and e (when they exist) in column c, and under the row where they come from. Then copying the beginning of the row. In order to obtain: a1|b1|c1 a1|b1|d1 a1|b1|e1 a2|b2|c2... (1 Reply)
Discussion started by: lucasvs
1 Replies

8. Shell Programming and Scripting

awk: Transpose csv row to column.

Hello, am I new to awk, and I am tryint to: INPUT FILE: "73423555","73423556","73423557","73423558","73423559" OUTPUT FILE: 73423555 73423556 73423557 73423558 73423559 My useless code so far: #!/bin/awk -F ',' BEGIN { i=0; } (8 Replies)
Discussion started by: drbiloukos
8 Replies

9. Shell Programming and Scripting

awk-gsub on column-wise on each row

awk '{ gsub(/....=/,""); print }' want.dat >final.dat the above awk command which removes all the chars before and including '=' on the entire row. --thats what it meant be.:) but i need to remove text on column-wise on each row. many thanks, EM ---------- Post updated at 10:00 AM... (4 Replies)
Discussion started by: elamurugu
4 Replies

10. UNIX for Dummies Questions & Answers

awk question row into column

I have a csv file: test1.csv with 26 columns Sample: Data collected Comp1,,,,,,,,,,,,,,,,,,,,,,,,,Average Number of Arrivals with non Zero,0,0,0,0,0,0,0,0,0,...,0 %Utilization,0.1,0.23,0.14,...,0.36 Data collected Comp2,,,,,,,,,,,,,,,,,,,,,,,,,Average Number of Arrivals with non... (2 Replies)
Discussion started by: calitiggr
2 Replies
Login or Register to Ask a Question