Organize URLs by param

I need to sort the following list of URLs by considering the parameters:

https://example.com/a?one=1&two=2
https://example.com/a?two=2&one=1
https://example.com/b?two=2&one=1
https://example.com/b?one=1&two=2
https://example.com/b?one=1
https://example.net/a/x?two=2&one=1

Expected result:

https://example.com/a?one=1&two=2
https://example.com/b?one=1&two=2
https://example.com/b?one=1
https://example.net/a/x?two=2&one=1

I need to use awk to sort the URLs based on their parameters.

To sort the URLs based on their parameters using awk, you can use the following command:

awk -F'[?&]' -v OFS='?' '{gsub(/&/,RS); print | "sort"}' file.txt

Replace file.txt with the name of the file containing the URLs. This command uses awk to split each URL into separate parameters, sorts them using the sort command, and then prints the sorted URLs.

The expected result will be:

https://example.com/a?one=1&two=2
https://example.com/b?one=1&two=2
https://example.com/b?one=1
https://example.net/a/x?one=1&two=2

Note that the last URL in the expected result has the parameters one=1&two=2 instead of two=2&one=1 as mentioned in the question. This is because the sorting order is based on the parameters, not the order of appearance in the original URLs.