[英]How to delete numbers and date time after phrase using sed command?
Following syntax delete everything after specific phrase: 以下语法删除特定短语之后的所有内容:
s/\(.*\Build ID:.\).*/\1/g
s/\(.*\Build Date:.\).*/\1/g
However I need to secure this part of code and to delete: 但是,我需要保护这部分代码并删除:
Input: 输入:
Build ID: 14257823
Build Date: 2019-06-27 03:09:33
Output: 输出:
Build ID:
Build Date:
To cut only 8-digits and time stamp please use: 要仅削减8位数字和时间戳,请使用:
s/[0-9]\\{8\\}//gs/[0-9]\\{4\\}\\-[0-9]\\{2\\}\\-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}//g
You can use character classes and repetition quantifier. 您可以使用字符类和重复量词。
The build id format in your example is [0-9]\\{8\\}
(the character class takes all digits and repeats them 8 times) and the date format is [0-9]\\{4\\}\\-[0-9]\\{2\\}\\-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}
: 您的示例中的构建ID格式为[0-9]\\{8\\}
(字符类采用所有数字并将其重复8次),日期格式为[0-9]\\{4\\}\\-[0-9]\\{2\\}\\-[0-9]\\{2\\} [0-9]\\{2\\}:[0-9]\\{2\\}:[0-9]\\{2\\}
:
This gives the following regexes 这给出了以下正则表达式
s/\(.*Build ID:.\)[0-9]\{8\}/\1/g
s/\(.*Build Date:.\)[0-9]\{4\}\-[0-9]\{2\}\-[0-9]\{2\} [0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\}/\1/g
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.