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. Related SolutionsLinux Bash – How to Sort du -h Output by Size As of GNU coreutils 7.5 released in August 2009, sort allows a -h parameter, which allows numeric suffixes of the kind produced by du -h: du -hs * | sort -h If you are using a sort that does not support -h, you can install GNU Coreutils. E.g. on an older Mac OS X: brew install coreutils du -hs * | gsort -h From sort manual: -h, --human-numeric-sort compare human readable numbers (e.g., 2K 1G) Linux – Create file with variable value in Unix touch $YESTERDAY or echo "something" > $YESTERDAY to append: echo "something" >> $YESTERDAY Related TopicGrep to display folders which contain files which contain a stringLinux – High Server Crash Rates During Leap Second DayLinux – Capture piped multiline grep output into a variable
Best Answer
This should work:
You need to put quotes around it because of the space in your variable.