• 在线工具
  • - 计算器
    • 字符计数
  • - 下载
    • TikTok 下载
    • 抖音下载
  • - 网络工具
    • BASE64
    • Base64 转图片
    • 图片转 Base64
    • URL 编码
    • JavaScript
    • 时间戳
    • Unicode 转换器
    • JSON 格式化
    • 修改扩展名
    • 制作列表
    • CSS 优化器
  • - 加密工具
    • MD5 加密
    • 随机生成器
  • - 图像工具
    • 图像压缩
    • 二维码生成器
    • 二维码识别器
    • 壁纸预览
  • - 信息表
    • 血型遗传
    • 服装尺码
  • [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 加密 随机生成器 图像压缩 二维码生成器 二维码识别器 壁纸预览 血型遗传 服装尺码
  • 藤井聡太八冠、瀬戸際の戦い 将棋叡王戦、31日に第4局
    2024-05-29

    民藝・イズ・ビューティフル。 日本文化と黒人文化が融合する「アフロ民藝」とは?
    2024-05-30

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

    将棋叡王戦、藤井が勝ち最終局へ
    2024-05-30

    むのたけじ賞、名称変更 「生前に障害者差別発言」
    2024-05-31

    「ねこクラゲ」被告、脱税認める 原稿優先で申告せず、福岡地裁
    2024-05-31

    『マッドマックス:フュリオサ』に登場する「ある絵画」は何を意味しているのか? ギリシア神話と「ファム・ファタル」から考察する
    2024-06-01

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

    知られざる作品や作家との巡り合いが生まれる高円寺のギャラリーショップ。
    2024-06-02

    声優の増山江威子さん死去
    2024-06-03

    テレ東が警察密着番組の担当者らを懲戒処分
    2024-06-03

    建築家・白井晟一設計の個人住宅「桂花の舎」が江之浦測候所に移築へ
    2024-06-04

    開館10周年を記念。「広重 ─摺の極─」があべのハルカス美術館で開催へ
    2024-06-05

    石川九楊の個展「石川九楊大全」が上野の森美術館で2ヶ月連続開催へ
    2024-06-05

    「安全だと誰も言わない万博」爆発事故で教職員組合 大阪府に子供無料招待中止申し入れ
    2024-06-04

    3日間限定発売! 名作パントンチェアが新たな魅力を纏った限定カラーで登場。
    2024-06-05

    田名網敬一の巨大インスタレーションが、世界初大規模回顧展「田名網敬一 記憶の冒険」に登場。国立新美術館で8月7日から
    2024-06-06

    なぜ、いま「先住民の現代アート」なのか? 『美術手帖』2024年7月号は、「先住民の現代アート」特集
    2024-06-06

    美術家藤井光さん個展「終戦の日/WAR IS OVER」 希望か絶望か…大分・佐伯の地下弾薬庫跡にこだまする泣き声
    2024-06-07

    もしあの時に戻れたら…歌人・穂村弘が話題書『迷子手帳』で明かす、今も忘れられない「失敗」
    2024-06-07

    ©  Dopu Box
    💛