Skip to main content
Became Hot Network Question
Retag, make title more concise, change formatting
Source Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77

using awk command match How can I print values from a data file after a specific pattern then skip two rowsis found, and print nth columnone line skipped in between?

I have a data file named File-1, FirstFile-1. I havetohave to match a pattern "DATA_POINTS"DATA_POINTS, and then after skipping two rows/linesone line I want to print 6th column of the following lines.

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

  • File-1 example:
    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
    
  • Desired 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
    
S1 = A
S2 = B
S3 = C
S4 = D
S5 = E
S6 = F
S7 = U
S8 = W
S9 = L
S10= K
S11= U
S12= X

The pattern DATA_POINTS does not repeat in the file, and an exact match is desired.

Nearest Solution

Nearest Solution

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

Thanks in advance! I really Appreciate the help!!

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

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

Thanks in advance! I really Appreciate the help!!

How can I print values from a data file after a specific pattern is found, and one line skipped in between?

I have a data file named File-1. I have to match a pattern DATA_POINTS, and then after skipping one line I want to print 6th column of the following lines.

  • File-1 example:
    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
    
  • Desired 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
    

The pattern DATA_POINTS does not repeat in the file, and an exact match is desired.

Nearest Solution

awk '/DATA_POINTS/{i==0 ; i++; getline; print "S"i"=", $6}' File-1
edited tags
Link
AdminBee
  • 23.6k
  • 25
  • 55
  • 77
added 116 characters in body
Source Link
sai
  • 77
  • 1
  • 1
  • 8

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

O
T
H
E
R

D
Ahere ! some other data exist but all of them are totally different from the below data!
T
AIn 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!!

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

O
T
H
E
R

D
A
T
A


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!!

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!!

Source Link
sai
  • 77
  • 1
  • 1
  • 8
Loading