忽略大小写开关和插入符不能按预期使用grep

时间:2011-08-10 22:14:17

标签: grep osx-lion

给出以下文件:

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

以下两个命令可以正常运行:

grep -i '[:alpha:]' testfile

给出

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

grep '[:alpha:]' testfile

给出

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

grep '^[:alpha:]' testfile

and this one too<div>
and more words 123

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

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

应该确保该行以字母数字开头的插入符号已经搞砸了所有内容。为什么'这是一些单词'行和'开始上限'行没有匹配? 这是在Mac Lion上使用bash。

1 个答案:

答案 0 :(得分:0)

我相信你所寻找的是:

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