-1

Normal grep

wolf@linux:~$ egrep 4.4.4.4 data.csv 
A,4.4.4.4,4.4.4.5,4.4.4.6,3.3.3.3,3.3.3.4
wolf@linux:~$ 

Since I've a lot of data to grep, I've put it on alias.

wolf@linux:~$ alias z="egrep $1 data.csv"
wolf@linux:~$ 

But it doesn't work

wolf@linux:~$ z 4.4.4.4
grep: 4.4.4.4: No such file or directory
wolf@linux:~$ 

It turns out that $1 was missing from the alias.

wolf@linux:~$ alias z
alias z='egrep  data.csv'
wolf@linux:~$

What was the reason behind this?

Wolf
  • 1,631

1 Answers1

5

Try a function instead of alias

z() { egrep -- "$1" data.csv; }

Output

$ z() { egrep -- "$1" data.csv; }
$ z 3.3.3.3
A,4.4.4.4,4.4.4.5,4.4.4.6,3.3.3.3,3.3.3.4
B,1.1.1.1,1.1.1.1,1.1.1.2,1.1.1.3,3.3.3.3
$