2018年8月21日 星期二

Linux 'grep' handbook

# Show lines containing any one of multiple keywords in a file 'foo.txt'
grep -e keyword1 -e keyword2 foo.txt

# Show lines containing 'keyword' in a file 'foo.txt'
grep keyword foo.txt

# Full (case sensitive) match
grep -w ""

# Show X lines before and Y lines after the line containing 'keyword' in a file 'foo.txt'
grep -B X -A Y keyword foo.txt
grep -C Z keyword foo.txt                    #when Z=Y=X

# Special characters.
grep '\$'                                                 # dollar sign
grep -P 'Modified\t' *                            # Tab

沒有留言: