• 線上工具
  • - 計算器
    • 字元計數
  • - 下載
    • TikTok 下載
    • 抖音下載
  • - 網路工具
    • BASE64
    • Base64 轉圖片
    • 圖片轉 Base64
    • URL 編碼
    • JavaScript
    • 時間戳
    • Unicode 轉換器
    • JSON 格式化
    • 修改副檔名
    • 製作列表
    • CSS 優化器
  • - 加密工具
    • MD5 加密
    • 隨機生成器
  • - 圖像工具
    • 圖像壓縮
    • QR 碼生成器
    • QR 碼識別器
    • 壁紙預覽
  • - 資訊表
    • 血型遺傳
    • 服裝尺寸
  • [email protected]
DopuBox
  • English
  • Español
  • Français
  • 日本語
  • 한국어
  • 简体中文
  • 繁體中文
全部 ニュース Meta Code 文化・アート
15個のLinux Grepコマンド使用例(実用、常用)
2021-11-25

コードのコピー
$ cat demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE. this line is the 1st lower case line in this file.
This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty. And this is the last line.
例01:指定した文字列を単一ファイルから検索する
コードのコピー $ grep "this" demo_file
this line is the 1st lower case line in this file.
Two lines above this line is empty. 例02:指定した文字列を複数のファイルから検索する
コードのコピー

$ cp demo_file demo_file1

$ grep "this" demo_* demo_file:this line is the 1st lower case line in this file.
demo_file:Two lines above this line is empty.
demo_file:And this is the last line.
demo_file1:this line is the 1st lower case line in this file.
demo_file1:Two lines above this line is empty. demo_file1:And this is the last line.
例03:大文字と小文字を無視してgrep-iを使用
コードのコピー $ grep -i "the" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE.
this line is the 1st lower case line in this file. This Line Has All Its First Character Of The Word With Upper Case.
And this is the last line.
例04:ファイルに正規表現をマッチさせる コードのコピー
$ grep "lines.*empty" demo_file
Two lines above this line is empty. Grepドキュメントから見ると、正規表現は次の一致操作に従う必要があります。
1.?         The preceding item is optional and matched at most once.
2.*          The preceding item will be matched zero or more times. 3.+         The preceding item will be matched one or more times.
4.{n}      The preceding item is matched exactly n times.
5.{n,}     The preceding item is matched n or more times. 6.{,m}    The preceding item is matched at most m times.
7.{n,m}  The preceding item is matched at least n times, but not more than m times.
例05:grep-wで完全一致を検索し、サブ文字列を含まない コードのコピー
$ grep -i "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE. this line is the 1st lower case line in this file. This Line Has All Its First Character Of The Word With Upper Case.
Two lines above this line is empty.
And this is the last line. コードのコピー
$ grep -iw "is" demo_file
THIS LINE IS THE 1ST UPPER CASE LINE IN THIS FILE. this line is the 1st lower case line in this file.
Two lines above this line is empty.
And this is the last line. 例06:grep-A,-B,-Cでafter/before/around行を表示する
コードのコピー
$ cat demo_text 4. Vim Word Navigation
You may want to do several navigation in relation to the words, such as:
* e - go to the end of the current word. * E - go to the end of the current WORD.
* b - go to the previous (before) word.
* B - go to the previous (before) WORD. * w - go to the next word.
* W - go to the next WORD.

ソース元URL:https://dopubox.com/article/p/97cee343e18d7f90

其他工具
  • 字元計數 TikTok 下載 抖音下載 BASE64 Base64 轉圖片 圖片轉 Base64 URL 編碼 JavaScript 時間戳 Unicode 轉換器 JSON 格式化 修改副檔名 製作列表 CSS 優化器 MD5 加密 隨機生成器 圖像壓縮 QR 碼生成器 QR 碼識別器 壁紙預覽 血型遺傳 服裝尺寸
  • レノンのギター4.5億円 ビートルズ関連最高落札額
    2024-05-30

    MURAKAMI × Liquem 夢のコラボアクセが再登場☆|長山智美 デザイン狩人
    2024-05-30

    ブームなぜ起きた? 東京国立近代美術館で「ハニワと土偶の近代」展
    2024-05-30

    社長「関係者や視聴者不安にさせた」と謝罪
    2024-05-30

    “家形埴輪”大集合、総選挙も 「住宅展示場の気分で」、奈良
    2024-06-01

    元アシスタントが語る Dr.スランプ「あのキャラ」の誕生秘話
    2024-06-01

    まだ無名だった作曲家エルガーが、婚約の贈り物として捧げた名曲【クラシック今日は何の日?】
    2024-06-01

    峰不二子役の増山江威子さん死去 声優、艶ある声でルパン翻弄
    2024-06-03

    河合隼雄賞に八木詠美さん「休館日の彼女たち」、湯澤規子さん「焼き芋とドーナツ」
    2024-06-02

    イタリア・ヴェローナの歴史あるレストランをパトリシア・ウルキオラが再解釈。
    2024-06-03

    稀代のピアニスト、マルタ・アルゲリッチの伝説の始まりはこの1曲から【クラシック今日は何の日?】
    2024-06-04

    知ってる? 「登録博物館等マーク」
    2024-06-05

    第34回福岡アジア文化賞受賞者が決定。大賞は真鍋大度
    2024-06-04

    国際博物館の日、今年のテーマは「学びと研究のための博物館」
    2024-06-04

    「KOGEI Art Fair Kanazawa 2024」開催決定
    2024-06-04

    青森で来年夏に音楽祭 沖澤のどかさんが総監督
    2024-06-06

    京都・祇園祭の「長刀鉾」稚児決まる 記者会見で「頑張ります」
    2024-06-06

    「江戸期より後の遺構」 世界遺産目指す佐渡の金山、一部除外勧告
    2024-06-06

    書評:「普通にラッセンが好き」と言えない現代美術界へ。原田裕規『評伝クリスチャン・ラッセン 日本に愛された画家』
    2024-06-06

    パートナーとの強い絆から生まれた、ベンジャミン・ブリテンの代表作【クラシック今日は何の日?】
    2024-06-06

    ©  Dopu Box
    💛