Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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 ?
share|improve this question

1 Answer 1

up vote 2 down vote accepted

This should work:

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

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

share|improve this answer
2  
Shells don't like spaces around the =. –  Dennis Williamson Feb 1 '10 at 6:14
    
Good point, corrected :) –  einstiien Feb 1 '10 at 6:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.