gpeng@LT-GEPENG ~
$ cat tmp
lllll
lllll
skdfksdfas
lllll
skdfksdfas
kkkk
gpeng@LT-GEPENG ~
$ perl -nle 'print unless $a{$_}++' tmp
lllll
skdfksdfas
kkkk
2009/11/11 Haiyan Lin <linhy0120@gmail.com>:
> 试了一下,得到下面的信息:
>
> [linhy@localhost try]$ more lll
> lllll
> lllll
> skdfksdfas
> lllll
> skdfksdfas
> kkkk
> [linhy@localhost try]$ perl -nle "print unless $a{$_}++;" lll > ll
> Can't modify anonymous hash ({}) in postincrement (++) at -e line 1, near
> "}++"
> Execution of -e aborted due to compilation errors.
>
>
>
> ----- Original Message -----
> From: "Tiger Peng" <tigerpeng2001@gmail.com>
> To: <perlchina@googlegroups.com>
> Sent: Wednesday, November 11, 2009 11:20 PM
> Subject: [PerlChina] Re: 请教哈:将文件中重复的行,替换,只保留一行
>
>
>> 试试:
>> perl -nle 'print unless $a{$_}++' infile > outfile.
>> 如果文件太大,要用很多memory。
>>
>> 2009/11/11 Haiyan Lin <linhy0120@gmail.com>:
>>>
>>> 希望保留原顺利,对于重复行,只保留首次出席的那行
>>>
>>>
>>> ----- Original Message -----
>>> From: "TBY" <tangboyun@hotmail.com>
>>> To: "PerlChina Mongers 讨论组" <perlchina@googlegroups.com>
>>> Sent: Wednesday, November 11, 2009 7:36 PM
>>> Subject: [PerlChina] Re: 请教哈:将文件中重复的行,替换,只保留一行
>>>
>>>
>>>> 用hash有问题的吧,行顺序全打乱了要紧么?
>>>>
>>>> 用uniq是最好的。
>>>> >
>>>>
>>>
>>>
>>> >
>>>
>>
>> >
>>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
您收到此信息是由于您订阅了 Google 论坛"PerlChina Mongers 讨论组"论坛。
要在此论坛发帖,请发电子邮件到 perlchina@googlegroups.com
要退订此论坛,请发邮件至 perlchina+unsubscribe@googlegroups.com
更多选项,请通过 http://groups.google.com/group/perlchina?hl=zh-CN 访问该论坛
-~----------~----~----~----~------~----~------~--~---
没有评论:
发表评论