I have a file with data as follows:
STUDENT DETAILS
NAME MARKS STD
XYZ 20 I
RANK SCHOOL TEACHER GRADE
5 TTT ANON B
POSITION
5
STUDENT DETAILS
NAME MARKS STD
ABC 40 I
RANK SCHOOL TEACHER GRADE
5 TTT ANON A
POSITION
5
I want my output as:
NAME MARKS STD RANK SCHOOL TEACHER GRADE POSITION
XYZ 20 I 5 TTT ANON B 5
ABC 40 I 5 TTT ANON A 5
I have tried finding the pattern STUDENT DETAILS
through awk
and printing 2nd, 5th and 8th lines after that. But the line needs to be concatenated.
I ran:
awk '/STUDENT DETAILS/{nr[NR];nr[NR+2]; nr[NR+5]; nr[NR+8]}; END {for (i in nr) print nr[i]}' file.txt > filenew.txt
How can I achieve this?