Grep characters before and after match?

前端 未结 7 1500
长情又很酷
长情又很酷 2020-12-02 04:19

Using this:

grep -A1 -B1 \"test_pattern\" file

will produce one line before and after the matched pattern in the file. Is there a way to di

7条回答
  •  情深已故
    2020-12-02 04:55

    You can use regexp grep for finding + second grep for highlight

    echo "some123_string_and_another" | grep -o -P '.{0,3}string.{0,4}' | grep string
    

    23_string_and

提交回复
热议问题