Wednesday, July 25, 2007

Linux.shell.command: two usages of 'less'

As you know, 'less' is a very useful tool to view text files. Today I realize the two more functions new for me:

  1. You could use less to open more than one file in the buffer, just by ":p" or ":n" etc. to switch them
  2. If you have more than 1 key words to search, just use the way /wordone|wordtwo|wordmore and then enter, thus those 3 key words will be highlighted in the text body.

Friday, July 20, 2007

Linux:shell:grep how to use grep's result

mystr="IloveChina"
echo $mystr |grep China
echo $? #this will return 0
echo $mystr |grep USA
echo $? #this will return 1
#so you could use this returned value to justify if grep found the string.
# Or you use how many searched results returned to do this, for example,
echo $mystr |grep -c China # return 1 to you
echo $mystr |grep -c USA # return 0 to you
# so simply, you can use the number to justify if you found the results like
if [ `
echo $mystr |grep -c China` -ge 1 ]; then
echo "Yes, you are"
fi




Locations of visitors to this page