Monday, February 4, 2008

Grep Tricks

Grep Tricks #1
How to select multiple lines with grep before and after the matched pattern .

grep -B1 -A2 "DMA" message.txt

B[n]          n lines before matched pattern
A[n]          n lines after matched pattern

Grep Tricks #2
How to display(print) the line numbers of the matched pattern with grep.

grep -n "DMA" message.txt

n              prints line no

1 comment:

firstohit said...

this was helpful. thanks

Print chess board in command line

The following bash one-liner will print a chess board in a terminal (the script works for the shells bash and ksh only) for (( i = 1; i ...