1
3

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 1 year has passed since last update.

【Linux】grepコマンドで複数条件指定する方法

Posted at

AND検索

複数の文字列を含む行を取得するには以下のように実行します。

$ grep '1' sample.txt | grep '5'
12345

15の両方が含まれる行のみ取得できています。

OR検索

複数の文字列のいずれかが含まれている行を取得するには以下のように実行します。

$ grep -e '1' -e 'D' sample.txt
12345
ABCDE
123

または正規表現を使用して以下のように実行します。

$ grep -E '1|D' sample.txt
12345
ABCDE
123

上記どちらの方法でも1またはDを含んだ行を取得できています。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?