Question

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

Was it helpful?

Solution

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{$_}++'"'"' '

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top