grep應用實例

如果文件夾下存在如下file:

qapatch_Hspice.sp
qapatch_SmartSpice.sp

aaa.sp

spiceout.err
spiceout.log

當使用如下規則查找結果時要注意:command line的meta字符和grep的meta字符是不一樣的定義。

command line中*表示任意字符,而grep的meta字符表示重複前個字符0到多次。

1.

ls | grep '.*/.sp'

得到結果:

qapatch_Hspice.sp
qapatch_SmartSpice.sp

aaa.sp

 

2.

 ls | grep '.*sp'

得到結果:

qapatch_SmartSpice.sp

aaa.sp

spiceout.err
spiceout.log

 

3.

ls | grep '*sp'

得到結果:

 

4.

如果不用ls,則grep將在

qapatch_Hspice.sp
qapatch_SmartSpice.sp

aaa.sp

spiceout.err
spiceout.log

中去查找相對應的行是否符合pattern的定義。

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章