gpt4 book ai didi

unix - 在 Unix 中获取 grep -E 的日期格式

转载 作者:行者123 更新时间:2023-12-04 02:09:50 24 4
gpt4 key购买 nike

我用下一个格式在我的文件上写日期

date +%a-%b-%d-%Y

我在练习中的目标是获取我文件中的日期列表。
我知道我需要用 grep -E 来做这件事,但我不知道如何正确放置日期格式。

所需输入:
"grep -E (the format of the dates I'm looking for)" ~/file1

期望的输出:
Tue-Oct-15-2013
Wen-Oct-16-2013
Wen-Oct-16-2013
Thu-Oct-17-2013

最佳答案

尝试以下操作:

grep -E '[[:alpha:]]{3}-[[:alpha:]]{3}-[[:digit:]]{2}-[[:digit:]]{4}' ~/file1

或者更简洁
grep -E '\w{3}-\w{3}-[0-9]{2}-[0-9]{4}' ~/file1

关于unix - 在 Unix 中获取 grep -E 的日期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19422215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com