문제

To filter non-consecutive lines of file, the below one-liner working fine:

cat filename | perl -ane 'print unless $a{$_}++'

However, when i tried to make it as an alias and do, its not working as expected

alias uniqlines " cat \!* | perl -ane 'print unless \$a{\$_}++' "

erroring out as below

   a: Undefined variable.

Using tcsh shell for SunOS operating system

도움이 되었습니까?

해결책

In bash this syntax works:

alias uniqlines="perl -ane 'print unless \$a{\$_}++' "

Here is a way that seems to work even in tcsh:

alias uniqlines 'perl -ane '"'"'print unless $a{$_}++'"'"' '

다른 팁

You want to use a function instead:

uniqlines(){ cat "$@" | perl -ane 'print unless $a{$_}++'; }

But this is pretty much just a fancy way of saying:

alias uniqlines=uniq
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top