pol*_*lym 10 shell grep string
假设我有一个这样的字符串:
title="2010-09-11 11:22:45Z"
Run Code Online (Sandbox Code Playgroud)
我怎样才能grep
日期本身而忽略引号/标题/ Z
?
该文件可以包含更多字符串,例如:
randomstring
title="2010-09-11 11:22:45Z"
title="disregard me"
Run Code Online (Sandbox Code Playgroud)
所以我只想grep
用一个grep
命令来加时间戳。
cuo*_*glm 16
使用GNU grep
,您可以执行以下操作:
$ echo 'title="2010-09-11 11:22:45Z"' | grep -oP 'title="\K[^"]+'
2010-09-11 11:22:45Z
Run Code Online (Sandbox Code Playgroud)
小智 5
如果输入只有这种格式,那么下面的命令将很容易解决你的问题
echo "title=\"2010-09-11 11:22:45Z\"| cut -d '"' -f2
Run Code Online (Sandbox Code Playgroud)