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