1月 152009
 

----------------------------------------------
linuxコマンドの正規表現
----------------------------------------------
■grepコマンド
検索にはgrepを使う。
「grep」コマンド
意味:指定されたパターンの文字列をファイル内から検索する。
書式:grep [オプション] 検索パターン [ファイル名]
オプション:
-c・・・マッチした行数だけを出力する
-i・・・大文字と小文字を区別しない
-n・・・マッチした行を行番号付きで出力する
-v・・・マッチしない行を出力する
複数組み合わせることもできる。-ciとか
*grepコマンドにメタキャラクタを用いた例。
textfileはファイル名。
行頭が「th」という文字列を含んだ行を除いて出力します。ちなみにメタキャラクタを指定する時には「’that’」のように引用符「’」で囲みます。
(例)
$ grep -v ‘^th’ textfile
(結果)
I am john
basket ball

よく読まれている記事

この記事を読んだ人は次の記事も読んでいます:

このエントリーをはてなブックマークに追加
はてなブックマーク - grep 文字列検索 linuxコマンドの正規表現
[`google_buzz` not found]
[`yahoo` not found]
[`livedoor` not found]
[`friendfeed` not found]
[`tweetmeme` not found]
[`grow` not found]
[`evernote` not found]

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)