grep limited characters - one line grep limited characters - one line unix unix

grep limited characters - one line


You could use a combination of grep and cut

Using your example I would use:

grep -sRn 'wp-content' .|cut -c -40grep -sRn 'wp-content' .|cut -c -80

That would give you the first 40 or 80 characters respectively.

edit:

Also, theres a flag in grep, that you could use:

-m NUM, --max-count=NUM          Stop reading a file after NUM matching lines.

This with a combination of what I previously wrote:

grep -sRnm 1 'wp-content' .|cut -c -40grep -sRnm 1 'wp-content' .|cut -c -80

That should give you the first time it appears per file, and only the first 40 or 80 chars.


 egrep -Rso '.{0,40}wp-content.{0,40}' *.sh

This will not call the Radio-Symphonie-Orchestra, but -o(nly matching).

A maximum of 40 characters before and behind your pattern. Note: *e*grep.


If you change the regex to '^.*wp-content' you can use egrep -o. For example,

egrep -sRo '^.*wp-content' .

The -o flag make egrep only print out the portion of the line that matches. So matching from the start of line to wp-content should yield the sample output in your first code block.