awk 匹配字符串和打印 ID 字符串
Awk Match String and Print ID String
我正在删除我们系统上的旧 KMS 密钥并学习 bash。这个论坛对建议非常有帮助!
我想打印 2019 年创建的密钥 ID。这是我目前的过滤器..
输入:
./ksctl keys list -l 100 | egrep -w 'id|name|createdAt' | awk ' ~ /"2019/ { print }' > keylist.txt
输出:
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
etc..
太棒了,但是我还需要用这个匹配项打印的 KeyID。
期望的输出:
"createdAt": "2019-06-20T20:15:20Z",
"id": "asdf1234",
如果 id
行总是在 createdAt
行之后,请使用 getline;
来阅读它。
./ksctl keys list -l 100 |
egrep -w 'id|name|createdAt' |
awk ' ~ /"2019/ { print; getline; print }' > keylist.txt
我正在删除我们系统上的旧 KMS 密钥并学习 bash。这个论坛对建议非常有帮助!
我想打印 2019 年创建的密钥 ID。这是我目前的过滤器..
输入:
./ksctl keys list -l 100 | egrep -w 'id|name|createdAt' | awk ' ~ /"2019/ { print }' > keylist.txt
输出:
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
"createdAt": "2019-06-20T20:15:20Z",
etc..
太棒了,但是我还需要用这个匹配项打印的 KeyID。
期望的输出:
"createdAt": "2019-06-20T20:15:20Z",
"id": "asdf1234",
如果 id
行总是在 createdAt
行之后,请使用 getline;
来阅读它。
./ksctl keys list -l 100 |
egrep -w 'id|name|createdAt' |
awk ' ~ /"2019/ { print; getline; print }' > keylist.txt