I'm trying to have a list of processes that were run sorted by the user who ran them. i have an input file that looks like this:
1 UID PID PPID C STIME TTY TIME CMD
2 adz110 5344 5334 0 08:47 pts /2 00:00:00 bash
3 dmq292 6908 6854 0 Jun04 pts /1 00:00:00 bash
4 adz110 7227 7150 0 Jul11 pts /9 00:00:00 who
5 erg474 7466 7461 0 08:54 pts /10 00:00:00 ls
6 dmq292 7966 7960 0 Jun04 pts /13 00:00:00 assign1 . sh if of
7 xle135 8983 8636 0 08:59 pts /15 00:00:00 ssh ctf . cs . utsarr . net
8 zeh458 9057 1980 0 08:59 pts /7 00:00:00 vim prog . c
9 rslavin 9150 9139 0 08:59 pts /16 00:00:00 ps - af
10 xle135 8636 8628 0 08:58 pts /15 00:00:00 bash
Unfortunately I'm unable to use any options of the sort command for this assignment. I can use sort, just no options. Primarily, I'll have to use awk for this. I have the output pretty close to how I need it, just not quite there. This is how it prints out:
User: adz110
bash
User: dmq292
bash
User: erg474
ls
User: xle135
ssh
User: zeh458
vim
User: rslavin
ps
So, it no longer lists adz110, dmq292, and xle135 twice. However, the second command that each user ran is not there. Tinkering around with it, I did get it to print out that information, but it was the whole line and it would print out one user below where I needed it.
gawk '/^[a-z]/ { if(!x[$1]++) print "User: "($1)"\n\t"" "$8; else if(x[$1]++) print "\t "x[$NF] };
'
This was supposed to be the end result:
User : adz110
2 bash
3 who
4 User : dmq292
5 bash
6 assign1 . sh if of
7 User : erg474
8 ls
9 User : xle135
10 bash
11 ssh ctf . cs . utsarr . net
12 User : zeh458
13 vim prog . c