linux - grep 某个单词,其前 10 个字符从 20 个字符中已知,最后 10 个字符是动态的
问题描述
我正在运行一个内部调用 python 文件的 abcd.sh 文件,python 脚本给出了一些输出,我正在接受一些变量并尝试 grep 一些单词,其起始 10 个字符从 20 个字符中已知,最后 10 个字符是动态的,这个词是多次的。
我想grep这个词。例如:在下面的日志示例中,我想搜索修复的"Request-Id-12977-1233"
位置"Request-Id"
1::com.demo.log.Demo::main::Sat Dec 15 01:42:43 EST 2012:: requestID: Request-Id-12977-1233 Demo::main
1::com.demo.log.Demo::main::Sat Dec 2012:: requestID: Request-Id-12977-1233 Demo::main
1::com.demo.log.Demo::main:: 2012:: requestID: Request-Id-12977-1233 Demo::main
1::com.demo.log.Demo::main: requestID: Request-Id-12977-1233 Demo::main
解决方案
我终于得到了答案,我之前尝试过这个但没有成功,可能是那里有一些错误。--获取python脚本的响应
initiateResponse=$(python pythonscript.py argument1 "argument2" "arguments3")
-- 回显输出,然后管道 grep,然后管道尾取最后一个值,因为有多个
requestId=$(echo initiateReposnse | grep -o "Request-Id-\w*" | tail -n 1)
echo "request Id $ requestId"
推荐阅读
- java - uml 类中缺少返回类型
- amazon-web-services - 如何操作 AWS AppSync 和 GraphQL 以符合 DynamoDB 最佳实践?
- regex - antlr解析器贪婪吗?
- sqlite - SQLite UNIQUE 冲突解决排序
- php - 如何通过 Docker 安装 PHP Composer 并像在本地安装一样使用?
- firebase - 可以将用户 ID 存储为 Firestore 文档中字段的键吗?
- python - 索引 Pandas MultiIndex 时如何避免排序?
- java - 想知道为什么在 IF 条件下 k 值不同
- reactjs - 如何有效地组织 Firestore 方法和连接
- c# - 如何在 Unity 中显示图像的实时更新?