Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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/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, i.e. for the above example only 1 is displayed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

Using sed

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading