user1228191
user1228191

Reputation: 691

How to use perl one-liner as an alias

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

Upvotes: 2

Views: 888

Answers (2)

pitseeker
pitseeker

Reputation: 2563

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

Upvotes: 2

michas
michas

Reputation: 26555

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

Upvotes: 0

Related Questions