Extract Velocity Data (Loc, Time, Velocity)

Hi ,

I am just learning awk and wanted to do the following :

Data (Velocity Data) Function of Hanvdel with time/velocity pair;

HANDVEL 20288 
20 9243 160 10658 204 11365 336 12651
444 13444 560 13937 652 14237 776 14537
924 15159 1052 15438 1168 15523 1316 15309
1452 15137 1736 15416 1824 15673 2164 16852
2516 17967 2864 18545 5996 22188
**location 20384 0 2 
HANDVEL 20384 
12 9243 172 10165 296 12201 352 12930
444 13444 564 14044 628 14280 748 14602
904 14987 1024 15137 1128 15266 1292 15180
1444 15073 1720 15288 1824 15459 2156 16831
2520 17988 2868 18567 5996 22188
**location 20480 0 2 
HANDVEL 20480 
4 9222 172 10208 248 11430 352 12951
436 13423 556 13959 648 14302 744 14537
896 14945 1024 15202 1132 15245 1296 15116
1436 15009 1720 15416 1828 15652 2132 16509
2300 17152 2524 17924 2852 18567 5996 22188
**location 20576 0 2

Outcome:
Wanted to capture "HANDVEL Value" "Time" "Velocity" per line

20288 20 9243
20288 160 10658
....
20384 12 9243
20384 172 10165

...

Appreciate your help.

nawk '/^HANDVEL/ {hand=$2}/^[0-9]/ {for(i=1; i<=NF;i+=2) print hand, $i, $(i+1)}' myFile

Thank you . I am currently running Red Hat Linux 2.1? and nawk is not available. Any suggestion of executing with regular awk or gawk.

try with awk

No output. I tried awk '/HANDVEL/ {print $2}' myfile and got all my HANDVEL Values . This suggested that awk works.

$awk '/HANDVEL/ {a=$2} /^[0-9]/ {for(i=1;i<=NF;i+=2){print a,$i,$(i+1)}}' input

Still no output.

post your original file contents

some awk's are picky....:

nawk '/^HANDVEL/ {hand=$2}/^[0-9]/ {for(i=1; i<=NF;i=i+2) print hand, $i, $(i+1)}' myFile

I revisted the code and try few things on the syntax. I got this to work with the following syntax:

awk '/HANDVEL/ (a=$2), /^[0-9]/ {for(i=1;i<=NF;i+=2)print a,$i,$(i+1)}' input
 

However it captured the ff: The Handel value is the same throughout althought it changes on the next HANDVEL sequence.
Any suggestions? Thanks

20096 HANDVEL 20096
0096 
20096 4 9165
20096 140 10249
20096 268 11430
20096 372 12265
20096 556 13573
20096 652 14152
20096 780 14602
20096 924 15095
20096 1064 15395
20096 1172 15502
20096 1336 15545
20096 1512 15459
20096 1756 15738
20096 1860 16059
20096 2176 17109
20096 2532 18160
20096 2928 18760
20096 5996 22188
20096 HANDVEL 20192
0096 
20096 16 9222
20096 176 10701
20096 264 11430

---------- Post updated at 08:58 AM ---------- Previous update was at 08:18 AM ----------

I have cleaned-up my original input to as ffs:

HANDVEL 20096 
4 9165 140 10249 268 11430 372 12265
556 13573 652 14152 780 14602 924 15095
1064 15395 1172 15502 1336 15545 1512 15459
1756 15738 1860 16059 2176 17109 2532 18160
2928 18760 5996 22188
HANDVEL 20192 
16 9222 176 10701 264 11430 368 12158
444 12737 548 13530 644 14152 784 14666
932 15159 1064 15459 1168 15545 1320 15502
1492 15416 1756 15738 1852 16016 2192 17045
2524 18138 2884 18695 5996 22188
HANDVEL 20288 
20 9243 160 10658 204 11365 336 12651
444 13444 560 13937 652 14237 776 14537
924 15159 1052 15438 1168 15523 1316 15309
1452 15137 1736 15416 1824 15673 2164 16852
2516 17967 2864 18545 5996 22188

what's wrong with the original solution?
I do follow the 'ff' explanation/notion....

your posted code is NOT what was suggested originally:

nawk '/^HANDVEL/ {hand=$2}/^[0-9]/ {for(i=1; i<=NF;i=i+2) print hand, $i, $(i+1)}'

Thank you for your comment.

  1. My Linux does not have nawk so I was trying to run awk. Typed "which nawk" returned with ... no nawk in......
  2. With awk, the posted original code did not work. There were no return and just hang. Have to ctrl c to clear it.
  3. Out of curosity I modified at the syntax as I posted and that runs BUT incorrect output.