Is this a homework assignment? Homework must be posted in the Homework & Coursework Questions Forum
and must contain a completely filled output template as described in the
Rules for Homework & Coursework Questions Forum. If this is not homework, please explain why you need to gather seemingly random lines from a file! Until we get a clear answer to the above questions, you won't get any more suggestions for a solution to your problem.
I will, however, make a few comments on what we have seen in this thread so far...
Now that I have added CODE tags to post #7 in this thread, we can see:
- what you are calling field 1 is seen by awk as fields 1 and 2,
- what you are calling field 3 is an empty string in line 3,
- you said you want fields 1, 2, and 3; but what you really want is fields 1, 2, and 4 (which in awk will be fields 1 and 2, 3, and 4 or 5 (depending on whether there is an empty field), and
- the sample data you said you want as your output doesn't come close to what you said you want as your output.
In your sample input file, the "3rd field" is empty on one line. Is that the only field that can be empty? Besides your "1st field" can any other fields contain <space> or <tab> characters (other than as field separators)?
And, even with the above realizations, I still don't know what you want. Are you trying to create HTML output or are you trying to create aligned text output?