The file I'm searching (fruit.text) looks something like the below snippet, the data appears in random order that I cannot control.
....fruit=apple,...qty=3,...condition=bad,....
...qty=4,...condition=great,...fruit=orange,...
...condition=ok,...qty=2,...fruit=banana,...
My Grep command is: grep -Eo 'fruit.[^,]*'\|'qty.[^,]*'\|'condition.[^,]*' fruit.txt
This results in output like:
fruit=apple
qty=3
condition=bad
qty=4
condition=great
fruit=orange
condition=ok
qty=2
fruit=banana
Which is correct, however, I'm looking for the output to be ordered as I specified in the grep cmd. ie, exactly like the below:
fruit=apple
qty=3
condition=bad
fruit=orange
qty=4
condition=great
fruit=banana
qty=2
condition=ok