【发布时间】:2017-03-28 18:10:05
【问题描述】:
Windows 10。
grep 作为 git 安装的一部分安装。
>grep --version
grep (GNU grep) 2.27
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Mike Haertel and others, see <http://git.sv.gnu.org/cgit/grep.git/tree/AUTHORS>.
>git --version
git version 2.12.0.windows.1
使用记事本创建的文件 sample.txt 包含以下 3 行;
a
b
c
获取 grep 以返回以 'a' 或 'c' 开头的行;
>grep ^[ac].*$ sample.txt
a
c
(好的 - 正如预期的那样)
让 grep 返回以任何字符 除了 'a' 或 'c' 开头的行,即以 'b' 开头的行;
>grep ^[^ac].*$ sample.txt
a
c
为什么这不起作用?
【问题讨论】:
-
命令行使用插入符号表示转义,所以必须自己转义,试试
^^? -
干杯!将其发布为答案,我会接受。 (使用 ^^[^^ ... 虽然 "^[^ ... 也可以使用 - 双引号)。