Sort & removal of duplicates Linux Bash
The desired sort is in ascending order:
- Removal of any duplicates
- Special sort
Special sort
- Print out 2 lines that does NOT contain the word "gmail"
- and THEN print only ONE line that contains the word "gmail".
- Repeat
If there are no more lines that does NOT contain the word "gmail", then it should just print the remaining sentences that contains the word "gmail" in alphabetical order.
Example list
test1@gmail.com
test2@gmail.com
test1@hotmail.com
test3@gmail.com
test2@hotmail.com
test3@hotmail.com
test1@live.com
test2@live.com
Desired results
test1@hotmail.com
test2@hotmail.com
test1@gmail.com
test3@hotmail.com
test1@live.com
test2@gmail.com
test2@live.com
test3@gmail.com
This can be done in coding by making 2 arrays and inserting every line containing the word "gmail" into one array, and inserting the rest into another array and then print them out in preferred order, but how would this be possible in Linux Bash if possible at all?