compound grep
I am needing to grep a file to extract the date 'Aug 04'. I am using a script to automate this as I need it to scan the file and email the output.
<script> works (but not completely). I get all Aug data but I also get anything that has Aug and 04 on the line: file04 Aug 01 .... #!/bin/sh nowmonth=`date +%b` nowday=`date +%d` cat /home/input | grep $nowmonth | grep $nowday > mail -s ..... I really want to use: cat /home/input | grep $nowmonth $nowday > mail -s I try it but it gives me errors after the $nowmonth. grep: 04: No such file or directory. but it just does not seem to work right. Any ideas? (using RH 8.0) |
Re: compound grep
Quote:
2) Quote the string you want to grep for. So: grep "$nowmonth $nowday" /home/input | mail foo@bar.com |
awesome. thanks. guess i had always used cat to grep and didn't think of alternatives.
:) j-me |
An alternative to quoting is to make use of the regexps:
Note the use of "\ " which is the regexp of space instead of quotes. |
All times are GMT -5. The time now is 05:47 AM. |