如何删去重复行并保持顺序不变?

如何删去重复行并保持顺序不变?

文本如下:
I'm a student.
You are a teacher.
He is a farmer.
He is a farmer.
He is a farmer.
We are workers.
将重复行找到,并删去只留一行,并且文本顺序不能改变,如何用sed实现?

      
sed可以做行比较吗      
用 uniq 比较方便:
复制内容到剪贴板
代码:
cax@ibm:~/Desktop> cat a
I'm a student.
You are a teacher.
He is a farmer.
He is a farmer.
He is a farmer.
We are workers.
cax@ibm:~/Desktop> cat  a | sort
He is a farmer.
He is a farmer.
He is a farmer.
I'm a student.
We are workers.
You are a teacher.
cax@ibm:~/Desktop> cat  a | sort | uniq
He is a farmer.
I'm a student.
We are workers.
You are a teacher.
      
LZ要求顺序不变      
如果重复行挨在一起, 不用sort就可以了      
看来用awk比较方便!      
怎么个方便法      
引用:
原帖由 TUDOU01 于 2007-8-11 10:36 发表
文本如下:
I'm a student.
You are a teacher.
He is a farmer.
He is a farmer.
He is a farmer.
We are workers.
将重复行找到,并删去只留一行,并且文本顺序不能改变,如何用sed实现?
用 sed 有点儿难度       
引用:
原帖由 li-jiahuan 于 2007-8-11 15:42 发表
怎么个方便法
用 awk 这么个方便法:
引用:
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[30959 0] ; cat file
I'm a student.
You are a teacher.
He is a farmer.
He is a farmer.
He is a farmer.
We are workers.
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[30959 0] ; awk '{ if (!seen[$0]++) { print $0; } }' file
I'm a student.
You are a teacher.
He is a farmer.
We are workers.
-(dearvoid@LinuxEden:Forum)-(~/tmp)-
[30959 0] ; bye
      
又是这种伎俩:)