1
0

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 3 years have passed since last update.

【ターミナル】grepコマンド

Last updated at Posted at 2021-05-12

概要

grep:ファイル内の文字列を検索するコマンド

検索例

基本検索

$ grep 検索正規表現 ファイル名

and検索

$ grep 検索文字列 ファイル名 | grep 検索文字列2

正規表現を使うことで1文の中でand検索ができる

$ grep スタートの検索文字列.*終わりの検索文字列 ファイル名

【正規表現】
.→ 何らかの文字、* →直前の文字の0個以上の繰り返し

and検索例

$ grep r.*p work/*

オプション一覧

-i

大文字と小文字を区別せず検索

-E

拡張正規表現で検索

-e

一致処理に指定した正規表現で検索

-v

一致しないものを検索

-n

検索結果に行番号を表示

-l

検索結果にファイル名のみ表示

-h

検索結果にファイル名を表示しない

-o

検索結果に一致した文字を表示

-r

ディレクトリ内も検索対象とする

-L

検索した結果、該当しなかったファイルを表示

参考

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?