Linux 从日志文件中剪切模式
Linux cut pattern from log file
我有 json 日志文件,但不仅 json
我需要 cut/remove 不是 json 的所有内容,结构如下所示:
2010-10-10 10:10:10 vibez.dev and here starts json {xxxx:xxxx, etc}
when json ends, next line with same info begins.
我试过 cut -d 命令,但它对我不起作用
尝试
sed -e 's/^.*\{/{/' [logfile]
这应该删除每行中第一个大括号之前的所有内容。
这完成了工作:
less file.json | awk -F ' {' '{printf("{%s}\n", )}' > result.json
假设 JSON 代码从 space 分隔文件的第 4 列开始,您可以简单地使用
cut -f 4- -d ' ' foo.txt
获取JSON代码
我有 json 日志文件,但不仅 json 我需要 cut/remove 不是 json 的所有内容,结构如下所示:
2010-10-10 10:10:10 vibez.dev and here starts json {xxxx:xxxx, etc}
when json ends, next line with same info begins.
我试过 cut -d 命令,但它对我不起作用
尝试
sed -e 's/^.*\{/{/' [logfile]
这应该删除每行中第一个大括号之前的所有内容。
这完成了工作:
less file.json | awk -F ' {' '{printf("{%s}\n", )}' > result.json
假设 JSON 代码从 space 分隔文件的第 4 列开始,您可以简单地使用
cut -f 4- -d ' ' foo.txt
获取JSON代码