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

Grepメモ①

Last updated at Posted at 2025-09-08

[grep]
自分が使うGrepのメモ

  • 大文字・小文字を区別しない(-i)
    grep -i "検索文字列" 対象ファイル
  • 再帰的に検索(-r)
    grep -i "検索文字列" -r 対象フォルダ
  • 出力結果に行番号を追加(-n)
    grep -n -i "検索文字列" -r "対象フォルダ"
  • 一致部分に色付け(--color)
    grep -n --color -i "検索文字列" -r "対象フォルダ"
  • 不要な文字列の除去(-v)
    grep -v "除去する文字列" -r "対象フォルダ"
  • 対象の行前後2行を出力(-C)
    grep -C 2 "検索文字列" -r "対象フォルダ"
  • 検索結果にフィアル名を表示する
    grep -h -i "検索文字列" -r "対象フォルダ"
  • 検索結果にファイル名のみを表示する(-l)
    grep -l -i "検索文字列" -r "対象フォルダ"
  • 拡張正規表現:OR(-E)
    grep -n -E "正規表現1|正規表現2" -r "対象フォルダ"
  • 拡張正規表現:OR(-e)
    grep -n -e "正規表現1" -e "正規表現2" -r "対象フォルダ"
  • 正規表現:AND(|)
    grep -i "検索文字列" 対象ファイル | grep -i "検索文字列"
  • ファイルへの出力(>)
    grep "検索文字列" 対象ファイル > 出力ファイル
  • 拡張正規表現:IPaddress(-E)
    grep -E "([0-9]{1,3}[.]){3}[0-9]{1,3}" 対象ファイル
  • IPaddressの該当部分のみ抽出
    grep -o -E "([0-9]{1,3}[.]){3}[0-9]{1,3}" 対象ファイル
  • 検索文字列の前後を表示
    grep -o '.{0,10}検索文字列.{0,10}' ファイル名
  • コメントアウト行と空行を省く
    grep -v -e '^\s*#' -e '^\s*$' filename
  • エスケープ
    grep '.go.jp'

参考資料

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