Answers for "grep return n characters before or after match"

1

grep return n characters before or after match

# Basic syntax:
grep -o -E '.{0,3}string.{0,4}' your_file.txt
# Where:
#	- This expression returns 3 characters before string and 4 after
#	-o specifies returning only the matching text, not the entire line
#	-E specifies allowing extended regular expressions (some answers
#		change this to -P, but that doesn't work on macOS)
Posted by: Guest on May-08-2021

Code answers related to "Shell/Bash"

Browse Popular Code Answers by Language