Not sure what OS you're running and this might be a tad over kill, but it may help you figure out your own solution:
for USER in `who | awk '{print $1}' | uniq`;do echo "PROCESSES RUN BY $USER";ps -a -u $USER;done
This one-line for loop loops through the names listed by the who command. Awk grabs the first column containing the names ($1), and uniq makes sure any duplicates are omitted. Then a header (PROCESSES RUN BY) followed by the user's name is printed. Under this heading are the processes being run by that particular user.
I have a question, when I do ps -au xxx, I get an answer for user xxx.. I have a filename call abc and when I do head -1 abc i get an output of xxx too. Why can't I do ps -au head -1 abc?
This is quite a simple question I have a file with my username in it.
So if I type cat filename, I get felix.whoals
TO show the current process that I am doing, I need to type ps -au felix.whoals
I want to get my username from the filename that I have created.
I was trying with ps -au | cat filename but this gives me an error.
Does anyone know how can I check my current processes by getting my username from the filename instead of entering it manually?
So this cannot be solved without awk and sed? I do not want to use these two commands because I want to use the long way to do it. Do you have another solution without using awk?
There might be 1000 good ways to do this, but you probably won't find one any better, shorter, or less complicated. The example can be done in one line, just takeout the newlines and the print statement. If you want to print the cmd, the statement probably needs to look like: print(cmd); (notice the parens and semi colon).