Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图只匹配这种格式的文本文件中的数字:
> 1234
我正在循环运行文件。每一行都在$i
$i
$i | grep "\d{4}"
输出如下所示:
> 1234 > 5678
为什么它仍然输出>?我想删除那些。
>
从man grep
man grep
-o, --only-matching Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line.
尝试grep -o ....
grep -o ....
测试:
i="> 1234" $ echo "$i" > 1234 $ echo "$i" | grep -oP "\d{4}" 1234