Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Kenneth Lum
Kenneth Lum

Posted on

     

To grep for a word and its adjacent characters

Sometimes we may want to grep for some words, and because the line is too long, sometimes even the whole file on one single line if it is a generated file, we may only want to see some characters before and after the match.

In that case, we can use something like:

grep-o-E'.{30}theword.{30}' somefile.html
Enter fullscreen modeExit fullscreen mode

or

curl https://somewebsite.com |grep-o-E'.{30}theword.{30}'
Enter fullscreen modeExit fullscreen mode

The-E says to treat it like it is egrep, and-o means only output the matched characters but not the whole line.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Web Front End developer. Worked at Apple, Intuit, and Facebook before
  • Location
    Silicon Valley
  • Joined

More fromKenneth Lum

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp