问题原文
原帖链接 · Taylor Halliday · CC BY-SA 3.0
I have a process that tails our AWS CloudWatch logs. It works great, except for the fact that every line is prepended by the CloudWatch group and container ID. For example:
core-api 04a7ce3daf83aa018a92eb4a613c87354695dc8219f213697f7f786b81d4d [PROD] - INFO: GET 200 - 5ms
core-api 04a7ce3daf83aa018a92eb4a613c87354695dc8219f213697f7f786b81d4d [PROD] - INFO: POST 200 - 7ms
Is there a way to pipe my logs command I use with some type of filter to only show the line info after [PROD] -?
已采纳解答
原帖链接 · Michael Hampton · CC BY-SA 3.0
You can try using cut to cut out the columns you are interested in.
tail -f whatever | cut -d ' ' -f 3-
[PROD] - INFO: GET 200 - 5ms
[PROD] - INFO: POST 200 - 7ms
This -d sets a space as the field delimiter, and -f specifies to display only the third and subsequent fields.
Specifying fields can get more complex, too. Suppose you only really want to get rid of that annoying useless second field. You can then specify -f 1,3-.
core-api [PROD] - INFO: GET 200 - 5ms
core-api [PROD] - INFO: POST 200 - 7ms
See the cut man page for more things you can do with this command.
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
