简体   繁体   English

此 SED 命令有什么作用?如何针对我的用例对其进行修改?

[英]What does this SED command do and how can I modify it for my use case?

I have been asked to fix someone else code so im unsure how the command actually works as ive never had to work with regex type code.我被要求修复其他人的代码,所以我不确定该命令实际上是如何工作的,因为我从来不需要使用正则表达式类型代码。

sed -r 's/([0-9]{2})\/([0-9]{2})\/([0-9]{4})\s([0-9]{2}:[0-9]{2}:[0-9]{2})/\3\/\1\/\2 \4/g'

This code reads the below txt file and is 'meant' to display the number in bold below.此代码读取下面的 txt 文件,并且“旨在”在下面以粗体显示数字。

placeholder_name                    01/01/2022 12:00:00  01/01/2022 12:00:01  STATUS    12345/15     50

This is output to a new temp file but the issue is that only the first character in the number after the '/' is displayed, ie for the above example only 1 is displayed.这是输出到一个新的临时文件,但问题是仅显示“/”之后数字中的第一个字符,即对于上面的示例,仅显示 1。

How would I modify the above command to take the full number after the '/'.我将如何修改上述命令以获取“/”之后的完整数字。 Alternatively, if there is a nicer/better way to do this id be happy to hear it或者,如果有更好/更好的方法来做到这一点,我很高兴听到它

Note: The number in bold has a range of 1-99注:粗体数字范围为 1-99

Using sed使用sed

$ sed -E 's#.*/([[:digit:]]+).*#\1#' input_file
15

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM