Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, using Bash-Linux I want to print on an out put file many strings of different lines of an input file. awk ' /^KEYWORD/ {array1[NR+2]}

Hello, using Bash-Linux

I want to print on an out put file many strings of different lines of an input file.

awk ' /^KEYWORD/ {array1[NR+2]} ;NR in array1{print $1,$2};/^KEYWORD/ {array2[NR+6]}; NR in array2{print $2,$3,$4,$7}; /^KEYWORD/ {print $3,$2}' $inputfile>> $output_file

As you can see the line that starts with the word KEYWORD is my landmark. My problem is that I want to print the above in the order that I wrote them. But, the last strings I want to print in the output file ( /^KEYWORD/ {print $3,$2}' ) , in the input file is above the rest strings (it is in the same line with the keyword, but the rest string that I want to print first (^KEYWORD/ {matrix1[NR+2]} ;NR in matrix1 {print $1,$2};/^KEYWORD/ {matrix2[NR+6]}; NR in matrix2 {print $2,$3,$4,$7}) are 2 or 6 line below).

So in the output file it prints them wrong.

How can I determine the right order? How can I determine to print the strings in the order I give them in the awk command?

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe the new structures for the HRM function. page 676

Answered: 1 week ago