Question: I have to grep through some JSON files in which the line lengths exceed a few thousand characters. **How can I limit grep to display context up to N characters to the left and right of the match?** Any tool other than grep would be fine as well, so long as it available in common Linux packages.

This would be example output, for the **imaginary grep switch Ф**:

```
$ grep -r foo *
hello.txt: Once upon a time a big foo came out of the woods.

$ grep -Ф 10 -r foo *
hello.txt: ime a big foo came of t

```

Answer: 
Try to use this one:

```
grep -r -E -o ".{0,10}wantedText.{0,10}" *

```

**-E** tells, that you want to use extended regex

**-o** tells, that you want to print only the match

**-r** grep is looking for result recursively in the folder

**REGEX:**

*{0,10}* tells, how many arbitrary characters you want to print

**.** represents an arbitrary character (a character itself wasn't important here, just their number)

**Edit:** Oh, I see, that Joseph recommends almost the same solution as I do :D
**Piping stdout to `cut` with the `-b` flag; you can instruct grep's output to only bytes 1 through 400 per line.**

```
grep "foobar" * | cut -b 1-400

```