Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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.