Linux – How to use grep commend with variable

greplinux

How can i use grep commend with variable ?

  • I stored ' Feb 1 ' (future it will be changeable) to variable 'date'.
  • Now i want to grep this variable 'date', How can i do this ?

Best Answer

This should work:

DATE='Feb 1'
grep "$DATE" [filename]

You need to put quotes around it because of the space in your variable.