KYOSS
The Kentucky Open Source Society




KYOSS General Forum
Topic: grepall - a shell script using grep


There are 3 posts on this topic:
Posted by frappyjohn (Msg), 8:33 pm Feb 12, 2014:
grepall - a shell script using grep
#!/bin/bash
grep -i "$*" *[^~] | less

Send private message to frappyjohn
Posted by frappyjohn (Msg), 11:24 pm Feb 18, 2014:
At our February meeting, Barton indicated it is better to...
At our February meeting, Barton indicated it is better to use "$@" instead of "$*":

grep -i "$@" *[^~] | less

Send private message to frappyjohn

Posted by frappyjohn (Msg), 5:48 pm May 9, 2014:
Even better, with color!
Even better, with color!

  • Adding --color=always to grep tells it not to suppress color when piping
  • Adding -R to less tells it to display the actual color, not the escape sequence passed thru the pipe
  • Adding -C 3 to grep causes it to show three lines of context before and after each occurrence found


#!/bin/bash
grep --color=always -C 3 "$@" *[^~] | less -R

Send private message to frappyjohn

Post your own comment to this topic.

0 most recent stories published:

1498689228x8046e40cf9