📜  grep 在匹配之前或之后返回 n 个字符 - Shell-Bash 代码示例

📅  最后修改于: 2022-03-11 14:49:48.106000             🧑  作者: Mango

代码示例1
# 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)