Skip to main content
3 of 4
edited tags
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

using awk command match a pattern then skip two rows and print nth column?

I have a data file named File-1, First I haveto match a pattern "DATA_POINTS" then after skipping two rows/lines I want to print 6th column.

File-1

here ! some other data exist but all of them are totally different from the below data!

In simple words following data is completely unique.


DATA_POINTS
12
   0.0000000000     0.0000000000     0.0000000000  20   !  A
   0.5000000000     0.5000000000     0.0000000000  20   !  B
   0.7500000000     0.5000000000     0.2500000000  20   !  C
   0.7500000000     0.3750000000     0.3750000000  20   !  D
   0.0000000000     0.0000000000     0.0000000000  20   !  E
   0.5000000000     0.5000000000     0.5000000000  20   !  F
   0.6250000000     0.6250000000     0.2500000000  20   !  U
   0.7500000000     0.5000000000     0.2500000000  20   !  W
   0.5000000000     0.5000000000     0.5000000000  20   !  L
   0.7500000000     0.3750000000     0.3750000000  20   !  K
   0.6250000000     0.6250000000     0.2500000000  20   !  U
   0.5000000000     0.5000000000     0.0000000000  20   !  X

Output

S1 = A
S2 = B
S3 = C
S4 = D
S5 = E
S6 = F
S7 = U
S8 = W
S9 = L
S10= K
S11= U
S12= X

Nearest Solution

I got this command from another qsn. this is working if the 6th column in a same row of pattern

awk '/DATA_POINTS/{i==0 ; i++; getline; print "S"i"=", $6}' file

Thanks in advance! I really Appreciate the help!!

sai
  • 77
  • 1
  • 1
  • 8