开发者

Ignore case switch and caret not working with grep as expected

开发者 https://www.devze.com 2023-03-26 22:47 出处:网络
Given the following file: this is some words and this one too<div> <html></html> and more words 123

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

精彩评论

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