I do not understand the practical use for something that takes a random number of examples (let us call this random number of examples example_count ) where example_count is an integer such that 1 <= example_count <= 20 and then takes 20 - example_count answers to produce 10 lines of output some of which have two examples, some of which have two answers, some of which have an example followed by an answer, and the rest have an answer followed by an example.
I could imagine needing to extract 10 examples and the 10 answers corresponding to those examples and creating 10 lines with the examples on the left and the answers on the right (but with the answers in random order) or creating 10 lines with the answers on the left and the examples on the right (but with the examples in random order), but neither of these match the output you say you want.
Is this a homework assignment? Homework and coursework questions can only be posted in the Homework & Coursework forum with a completely filled out homework template that is available in the special homework rules.
I would like you to know that it is not part of homework but is a process carried out by the local school teachers on a daily basis. To make life easier for them I suggested that it could be done using sone form of shell script and that is where I thought you guys came in.
Hopefully this clears and misunderstanding on my part.
You can run it as given exchanging "file" with your file's name. Or, put everything within but excluding the single quotes into the .awk file, and run like
(as RudiC suggested in post #10 in this thread) to get rid of the commas after all of the example#s in your output (and to allow the script to work when an example or answer contains more than one "word").
Please go back and look at your post #1 in this thread where you showed output exactly like that above with examples and answers in both columns of the desired output. Then look at post #2 where I said:
and in post #3 you stated:
which we all understood to be a clear statement that you wanted examples and answers mixed in the columns; not kept in separate columns.
So, now that you have changed your mind; please be very clear about what you want:
Do you want examples in the left column of output and answers in the right column of output?
Do you want answers in the left column of output and examples in the right column of output?
Do you want the script to randomly decide whether to put examples or answers in the left column and answers or examples, respectively, in the right column?
Do you want the script to interactively ask the user which field should be in the left column?
Do you want the script to default to putting examples in the left column and answers in the right column and accept an option to switch the order?
Or do you want the script to require an operand that specifies which data goes in the left column?
Please also tell us:
The output you said you want uses a single tab character to separate output fields. Is that really what you want, or do you want both output columns aligned?
The input shows a <comma> (or <comma><space>) as the input file field separator. What input field separator do you want to use? (Note that whatever field separator you choose to use will not be allowed to appear in any example and will not be allowed to appear in any answer!)
Do you have access to Perl?
That problem is solved in my solution in post number 8
Just copy and paste on your command line, change the example.data for your real filename:
Thanks everyone for your efforts, but I'm not remotely convinced that "it is not part of homework but is a process carried out by the local school teachers on a daily basis", so the thread is closed.