How to sort the files by size and based subdirectory un UNIX?

I have the below input data in a file and need to get the output as mentioned below. Need to sort the data by size(Asc/des)/by subdirectory

Below is the input which is there in a file:

120     /root/path2/part-00000-d3700305-428d-4b13-8161-42051f4ac5ed-c000.json
532     /root/path1/part-00000-9aa3e423-084b-406b-8c75-d50c369f1943-c000.json
100     /root/path1/Telephone-bill-September-2019-89051_path.doc
72      /root/path2/BishnuPrasadRout[5_0].doc
4       /root/path2/survey.csv
4       /root/path2/hello.c
4       /root/path1/pages.txt
4       /root/path1/hadoopexam.txt

Expected Output

120     /root/path2/part-00000-d3700305-428d-4b13-8161-42051f4ac5ed-c000.json
72      /root/path2/BishnuPrasadRout[5_0].doc
4       /root/path2/survey.csv
4       /root/path2/hello.c
532     /root/path1/part-00000-9aa3e423-084b-406b-8c75-d50c369f1943-c000.json
100     /root/path1/Telephone-bill-September-2019-89051_path.doc
4       /root/path1/pages.txt
4       /root/path1/hadoopexam.txt

Hi, try:

sort -t/ -k2,3r -k1,1rn -k4 file
120     /root/path2/part-00000-d3700305-428d-4b13-8161-42051f4ac5ed-c000.json
72      /root/path2/BishnuPrasadRout[5_0].doc
4       /root/path2/hello.c
4       /root/path2/survey.csv
532     /root/path1/part-00000-9aa3e423-084b-406b-8c75-d50c369f1943-c000.json
100     /root/path1/Telephone-bill-September-2019-89051_path.doc
4       /root/path1/hadoopexam.txt
4       /root/path1/pages.txt
1 Like

Yes! its worked. Thankyou
Could please explain the soultion

The sort options mean the following,
-t/ : split fields on the / character
-k2,3r : First, reverse (r) sort on the string that consists of fields 2 to 3 , which is root/path[12] in the example
-k1,1rn : Then Do a reverse numeric sort on the first field which is the file size
-k4 : Everything sofar being equal forward sort the remaining fields (file names).

Hope this helps..