grep a string with space
Hi All, I am using Sun 5.9. I am putting the value "Feb 10" in variable 'c' here. Code:
-bash-3.00$ c=`date | awk '{print $2 " " $3}'` Code:
-bash-3.00$ ls -lrth | grep $c Any other way out ? |
Put the $c in single quotes:
Code:
-bash-3.00$ ls -lrth | grep '$c' |
I would have said double-quotes (to allow the variable to be expanded)
|
Read the "quoting" section of the bash manual. I don't use a Sun system (nor the Sun OS), but - if the have a POSIX bash - try grep "$c" or grep /\'$c\'/.
|
Thanks pixellany and PTrenholme, double quotes is working fine.
I was trying awk/sed ;) Sometimes things are too simple and you try too hard. |
Another clue: you can simplify the assignment using the date format (no need to parse with awk):
Code:
c=`date +%b\ %e` |
All times are GMT -5. The time now is 02:05 PM. |