开发者

Ignore case switch and caret not working with grep as expected

Given the following file:

this is some words
and this one too<div>
<html></html>
and more words 123
Caps to begin
ASDFSDFSDF

the following 2 commands work as I would expect:

grep -i '[:alpha:]' testfile

gives

this is some words
and this one too<div>
<html></html>
and more words 123
Caps to begin
ASDFSDFSDF

and

开发者_JAVA百科grep '[:alpha:]' testfile

gives

this is some words
and this one too<div>
<html></html>
and more words 123
Caps to begin

but

grep '^[:alpha:]' testfile

and this one too<div>
and more words 123

and

grep -i '^[:alpha:]' testfile

and this one too<div>
and more words 123
ASDFSDFSDF

The caret which should ensure the line begins with an alphanumeric has messed everything up. Why is the 'this is some words' line and the 'Caps to begin' line not getting matched? This is using bash on Mac Lion.


I believe what you're looking for is:

grep '^[[:alpha:]]' testfile
grep -i '^[[:alpha:]]' testfile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜