Sort, group rows

I wrote script in bash which generates this report:

User1,admin,rep,User2,shell,path1,x1,r1
User2,admin,rep,User7,shell,path1,x1,r1
User3,admin,rep,User4,shell,path1,x1,r1
User4,admin,rep,User3,shell,path1,x1,r1
User5,admin,rep,User1,shell,path1,x1,r1
User6,admin,rep,User5,shell,path1,x1,r1
User7,admin,rep,User6,shell,path1,x1,r1
...

I would like so that (UserX):

User1,admin,rep,User1,shell,path1,x1,r1
User2,admin,rep,User2,shell,path1,x1,r1
User3,admin,rep,User3,shell,path1,x1,r1
User4,admin,rep,User4,shell,path1,x1,r1
User5,admin,rep,User5,shell,path1,x1,r1
User6,admin,rep,User6,shell,path1,x1,r1
User7,admin,rep,User7,shell,path1,x1,r1
...

How to do this ?
Thx

Hi mate,

What do u mean? Do u want to sort the entries according to one of the columns?

OK :o I got it !

I will c if I can help ..

Hi

Source report:

User1,admin,rep,User2,shell,path1,x1,r1
User2,admin,rep,User7,shell,path1,x1,r1
User3,admin,rep,User4,shell,path1,x1,r1
User4,admin,rep,User3,shell,path1,x1,r1
User5,admin,rep,User1,shell,path1,x1,r1
User6,admin,rep,User5,shell,path1,x1,r1
User7,admin,rep,User6,shell,path1,x1,r1
User8,admin,rep,,,path1,x1,r1
User9,admin,rep,,,path1,x1,r1
User10,admin,rep,,,path1,x1,r1
User11,admin,rep,,,path1,x1,r1
...

I'd like to assign user names with numbers User2,User7,User4,User3,User1... from the fourth column to the same users from the first column, so as to obtain the following report:

User1,admin,rep,User1,shell,path1,x1,r1
User2,admin,rep,User2,shell,path1,x1,r1
User3,admin,rep,User3,shell,path1,x1,r1
User4,admin,rep,User4,shell,path1,x1,r1
User5,admin,rep,User5,shell,path1,x1,r1
User6,admin,rep,User6,shell,path1,x1,r1
User7,admin,rep,User7,shell,path1,x1,r1
User8,admin,rep,,,path1,x1,r1
User9,admin,rep,,,path1,x1,r1
User10,admin,rep,,,path1,x1,r1
User11,admin,rep,,,path1,x1,r1
...

ps.
only users User2,User7,User4,User3,User1... from the fourth column have shell

Help me please.

something like this ?

$ awk 'BEGIN {FS=OFS=","} $4!="" {$4=$1} {print}' es.txt

Thank you very much :slight_smile: