开发者

Problem removing duplicate files using awk

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?


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


try using

$ ps -ef | sort | uniq
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜