grep有時顯示會變成空行 - Linux

By Edith
at 2011-06-06T11:19
at 2011-06-06T11:19
Table of Contents
我用鳥哥的文件做練習:
http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt
其中5,6,7,8,9,14這幾行是WINDOWS的結尾^M$,而我用的參數是
grep -n --color=auto ...,目的是看到行號和標示kwy word。
今天鳥哥示範『至少兩個 o 以上的字串』時,就需要 ooo*
grep -n --color=auto ooo* 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.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
可以抓到1,2,3,9,18,19沒問題,但我想說*代表0到無限所以我用任意字元.也可以
grep -n --color=auto oo.* 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.
9:Oh! The soup taste gmood.
18:google is the best tools for search keyword.
19:goooooogle yes!
但這時候第9行就消失了,變成空行在那邊。只要不用.,隨便改用%或是H等字元,
都不會鬼隱。
另外如果我把結果存成文字,兩種選項的內容一樣。而如果我把--color=auto拿掉的話,
第9行就會出現。
我用過別種關鍵字,發現鬼隱的條件有三個:
1.抓的內容是.*結尾
2.斷行是^M$
3.要加上顏色顯示的參數
現在雖然沒什麼大問題,但我實在很好奇為什麼會有這種結果,請問有人知道嗎?
--
起初,他們追殺共產主義者,我沒有說話,因為我不是共產主義者;
接著,他們追殺猶太人,我沒有說話,因為我不是猶太人;
後來,他們追殺工會成員,我沒有說話,因為我不是工會成員;
此後,他們追殺天主教徒,我沒有說話,因為我是新教教徒;
最後,他們奔我而來,卻再也沒有人站起來為我說話了。
《First They Came(他們首次來時)》,Martin Niemoller牧師(1892-1984)
--
http://linux.vbird.org/linux_basic/0330regularex/regular_express.txt
其中5,6,7,8,9,14這幾行是WINDOWS的結尾^M$,而我用的參數是
grep -n --color=auto ...,目的是看到行號和標示kwy word。
今天鳥哥示範『至少兩個 o 以上的字串』時,就需要 ooo*
grep -n --color=auto ooo* 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.
9:Oh! The soup taste good.
18:google is the best tools for search keyword.
19:goooooogle yes!
可以抓到1,2,3,9,18,19沒問題,但我想說*代表0到無限所以我用任意字元.也可以
grep -n --color=auto oo.* 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.
9:Oh! The soup taste gmood.
18:google is the best tools for search keyword.
19:goooooogle yes!
但這時候第9行就消失了,變成空行在那邊。只要不用.,隨便改用%或是H等字元,
都不會鬼隱。
另外如果我把結果存成文字,兩種選項的內容一樣。而如果我把--color=auto拿掉的話,
第9行就會出現。
我用過別種關鍵字,發現鬼隱的條件有三個:
1.抓的內容是.*結尾
2.斷行是^M$
3.要加上顏色顯示的參數
現在雖然沒什麼大問題,但我實在很好奇為什麼會有這種結果,請問有人知道嗎?
--
起初,他們追殺共產主義者,我沒有說話,因為我不是共產主義者;
接著,他們追殺猶太人,我沒有說話,因為我不是猶太人;
後來,他們追殺工會成員,我沒有說話,因為我不是工會成員;
此後,他們追殺天主教徒,我沒有說話,因為我是新教教徒;
最後,他們奔我而來,卻再也沒有人站起來為我說話了。
《First They Came(他們首次來時)》,Martin Niemoller牧師(1892-1984)
--
Tags:
Linux
All Comments

By Linda
at 2011-06-11T02:53
at 2011-06-11T02:53

By Rachel
at 2011-06-12T16:53
at 2011-06-12T16:53

By Victoria
at 2011-06-17T03:53
at 2011-06-17T03:53

By Rosalind
at 2011-06-17T23:23
at 2011-06-17T23:23

By Jake
at 2011-06-18T18:27
at 2011-06-18T18:27

By Faithe
at 2011-06-18T22:16
at 2011-06-18T22:16

By Joseph
at 2011-06-23T05:59
at 2011-06-23T05:59
Related Posts
ubuntu桌面被迫全螢幕

By Suhail Hany
at 2011-06-06T09:08
at 2011-06-06T09:08
Ubuntu虛擬鍵盤

By Carolina Franco
at 2011-06-05T21:17
at 2011-06-05T21:17
如何把雙系統中的Win空間挪給Linux用

By Emily
at 2011-06-05T20:08
at 2011-06-05T20:08
LXDE左下角開始選單字型設定

By Necoo
at 2011-06-05T19:11
at 2011-06-05T19:11
CentOS 4.7 無法安裝GNOME

By Adele
at 2011-06-05T16:42
at 2011-06-05T16:42