Question

Contents of part3.1.awk

{
current_line=$0
if (current_line!=prev)
{
    print $1 " -> " " -> " $5 " -> " $8
}
prev=$0
}

To get the list of processes, i run this in terminal. I want to get output with removed duplicates and sorted too.

$ps -ef | awk -f part3.1.awk | sort

What wrong am i doing?

Was it helpful?

Solution

You are sorting the output from the awk script, when you want to be sorting the input.

$ps -ef | awk -f part3.1.awk | sort

should be

$ps -ef | sort | awk -f part 3.1.awk

But I should tell you that you don't need awk to remove duplicates. sort -u will do this for you, as in

ps -ef | sort -u

OTHER TIPS

try using

$ ps -ef | sort | uniq
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top