简体   繁体   中英

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.

placeholder_name                    01/01/2022 12:00:00  01/01/2022 12:00:01  STATUS    12345/     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.

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

Using sed

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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