忽略大小写开关和插入符号无法按预期与 grep 配合使用

发布于 2024-11-29 03:03:11 字数 925 浏览 0 评论 0原文

给定以下文件:

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

以下 2 个命令按我的预期工作:

grep -i '[:alpha:]' testfile

Gives

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

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

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

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

插入符号应确保该行以字母数字开头,但已经把一切搞乱了。为什么“这是一些单词”行和“大写开头”行不匹配? 这是在 Mac Lion 上使用 bash。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨光如昨 2024-12-06 03:03:11

我相信您正在寻找的是:

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

I believe what you're looking for is:

grep '^[[:alpha:]]' testfile
grep -i '^[[:alpha:]]' testfile
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文