毎日Linux練習ジャンプ文字選択行頭^と行尾$
[dmtsai@study ~]$ grep -n '^the' regular_express.txt
12:the symbol '*' is represented as start.
このとき、12行目しか残っていません.12行目の行頭だけがtheの先頭ですからね~また、私が小文字の先頭にしたいなら、その行をリストアップしますか?次のようにできます.
[dmtsai@study ~]$ grep -n '^[a-z]' regular_express.txt2:apple is my favorite food.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.
12:the symbol '*' is represented as start.
18:google is the best tools for search keyword.
19:goooooogle yes!
20:go! go! Let's go.
最初の文字が大文字ではないことがわかります!上記のコマンドは、次のように置き換えることもできます.
[dmtsai@study ~]$ grep -n '^[[:lower:]]' regular_express.txt
よし!もし私が最初に英語のアルファベットを望んでいないなら、そうすることができます.
[dmtsai@study ~]$ grep -n '^[^a-zA-Z]' regular_express.txt1:"Open Source" is a good mechanism to develop programs.
21:# I am VBird# : grep -n '^[^[:alpha:]]' regular_express.txt
気づいたでしょう?その^記号は、文字集合記号(括弧[])の内と外では違います![]内では『逆選択』、[]外では行頭に位置づける意味を表します!はっきり分けてね!逆に考えてみると、私が見つけたいなら、行末は小数点に終わります(.)の行は、次のように処理されます.
[dmtsai@study ~]$ grep -n '\.$' regular_express.txt
1:"Open Source" is a good mechanism to develop programs.
2:apple is my favorite food.
3:Football game is not use feet only.
4:this dress doesn't fit me.
10:motorcycle is cheap than car.11:This window is clear.
12:the symbol '*' is represented as start.
15:You are the best is mean you are the no. 1.
16:The world <Happy> is the same with "glad".
17:I like dog.
18:google is the best tools for search keyword.
20:go! go! Let's go.
特に、小数点は別の意味(後述)を持つため、特殊な意味を解除するにはジャンプ文字()を使用しなければならないことに注意してください.でも、おかしいと思うかもしれませんが、5~9行目の一番後ろも.あ~どうして印刷できないの?ここではWindowsプラットフォームのソフトボディのブレークワードの判断に関与します!cat-Aを使用して5行目を取り出します.
[dmtsai@study ~]$ cat -An regular_express.txt | head -n 10 | tail -n 6
5 However, this dress is about $ 3183 dollars.^M$
6 GNU is free air not free beer.^M$
7 Her hair is very beauty.^M$
8 I can't finish the test.^M$
9 Oh! The soup taste good.^M$
10 motorcycle is cheap than car.$
9章ではLinuxとWindowsでのブレークワードの違いについて述べましたが、上記の表では5~9動作のWindowsのブレークワード(^M$)を見つけることができますが、通常のLinuxは10行目に表示されるような($)しかありません.だから、あの.もちろん$の直前ではありませんよ!5~9は捕まえられない!これで^と$の意味がわかりますか?さて、まず下の解答を见ないで、自分で考えてみて、それではもし私が探し出したいならば、どの行は《空白の行》で、つまり、この行はいかなる资料を入力していないで、どのように探しますか?
[dmtsai@study ~]$ grep -n '^$' regular_express.txt22:
行頭と行尾しかないので(^$)、これで空白を見つけることができます!また、プログラムスクリプト(shell script)や設定ファイルで、空白の行と先頭の行が注釈であることを知っているとします.そのため、他の人に参考にするときに、これらの資料を省略して高価な紙を節約することができます.どうすればいいですか.私たちは/etc/rsyslog.confというファイルを例に挙げると、出力の結果を自分で参考にすることができます.
[dmtsai@study ~]$ cat -n /etc/rsyslog.conf# CentOS 7 , 91 , # [dmtsai@study ~]$ grep -v '^$' /etc/rsyslog.conf | grep -v '^#'# 14 , 『 -v '^$' 』 『 』,
# 『 -v '^#' 』 『 # 』 !
多くのレイアウトを節約しますか?また、なぜ#の記号が出ない行をそのまま捨てるのかと聞かれるかもしれません.仕方ない!いくつかの注釈は設定と同じ行の後ろに書かれているので、#をつかむだけで削除すると、いくつかの設定も同時に削除されます.それは間違いが大きい~