5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

grepで部分一致検索

Posted at

意外と知られていませんが、grepで部分一致検索ができます。
json文字列からURLを抜き出す場合などに便利。

-o, --only-matching
マッチする行のマッチした部分だけを (それが空文字列でなければ) 表示します。 マッチした各文字列は、それぞれ別の行に書き出します。

◆サンプル

ubuntu@ubuntu-virtual-machine:~/work/grep$ cat json.txt  
{"image_urls":{"thumbnail":"http://abc.com/thumbnail.jpg","small":"http://abc.com/small.jpg"}}  

ubuntu@ubuntu-virtual-machine:~/work/grep$ egrep -o "http[^\"]+" json.txt  
http://abc.com/thumbnail.jpg  
http://abc.com/small.jpg
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?