$ grep [オプション] 検索する文字列 検索対象のファイル |
あるテキストファイルの文字列を検索するには grep というコマンドを使用します。
代表的なオプションを以下に示します。
表 6-4. grep コマンドのオプション
| -i | アルファベットの大文字と小文字を区別しないで検索します。 |
| -l | 検索結果をファイル名だけで表示します。 |
| -n | 行番号を表示します。 |
| -v | マッチしない行を表示します。 |
| -x | 文字列と完全に一致するものだけを検索します。 |
例えば、/usr/share/doc/FAQ/txt ディレクトリに存在する全ファイルを対象に、LILO という文字列を検索します。
$ grep LILO /usr/share/doc/FAQ/txt/* /usr/share/doc/FAQ/txt/ATAPI-FAQ:66: Update LILO or loadlin (whichever you prefer to use) as needed, /usr/share/doc/FAQ/txt/BLFAQ:243: to the file /etc/lilo.conf if you use LILO or to the end of the respective /usr/share/doc/FAQ/txt/BLFAQ:245: You will need to rerun LILO for the changes to take effect. The next time you /usr/share/doc/FAQ/txt/BLFAQ:273: get the LILO prompt and can't boot into Linux. What should I do? 省略 |