0

Would like to read 6th line (var=i), 9th line(var=j), 12th line (var=k) then output as first row then increment by 10 lines ( i+10;j+10;k+10) and output as second row , and so on ...

Input.txt

MN
LIST

DETAILS
AAAA             BBBB           CCCC
123421751116849  119865688385     IDLE

DATE             TIME             DDDD
150203           161044           123-42-50300-14481

EEEE
111394052866500

DETAILS
AAAA             BBBB           CCCC
123421825027128  119698116932     IDLE

DATE             TIME             DDDD
150204           183507           123-42-3200-10793

EEEE
352708042150790

DETAILS
AAAA             BBBB           CCCC
123421893844511  118675320014     IDLE

DATE             TIME             DDDD
150204           222245           123-42-50000-1823

EEEE
352663056076930

DETAILS
AAAA             BBBB           CCCC

Expected Output.txt

AAAA,BBBB,CCCC,DATE,TIME,DDDD,EEEE

123421751116849,119865688385,IDLE,150203,161044,123-42-50300-14481,111394052866500
123421825027128,119698116932,IDLE,150204,183507,123-42-3200-10793,352708042150790
123421893844511,118675320014,IDLE,150204,222245,123-42-50000-1823,352663056076930

I have tried below command and in-complete

awk 'BEGIN { FS" "; OFS=","} { for (i=6;j=9;k=12;i<=NR;j<=NR;k<=NR;i+10;j+10;k+10) print $i,$j,$j }'  Input.txt

Looking for your suggestions !!!

1 Answer 1

2

I'd use

awk -v RS=DETAILS -v OFS=, 'NR == 2 { print $1, $2, $3, $7, $8, $9, $13 } NR != 1 { print $4, $5, $6, $10, $11, $12, $14 }' filename

The trick is to split the file into records delimited by DETAILS rather than newlines and then pick out the appropriate fields from those records. The NR == 2 block is only to generate the header line. NR == 1 is the fluff before the first DETAILS and therefore ignored.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot Wintermute , It's working fine , I have accepted your answer and up-voted !!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.