I have a log where i want to apply a replace just inside a regexp match text.
Example, take this log line:
date machine text random text and yet more random text - status code
i want o replace the all spaces by a _ inside the text area, without replacing all other spaces in the log. the output would be this:
date machine text_random_text_and_yet_more_random_text - status code
To match the area i want to replace i have this regexp:
/machine \(.*\) - /
As the text is not standard, i can have one space to 20, so its hard to match it directly, so i match the start and the end of the substring.
Trying to use it i tried this:
sed `/machine \(.*\) - / s/ /_/g ' logfile
but of course, it will replace all spaces in the log, not just the matched substring.
I managed to do it with awk, by iterating and printing each field until i find the machine, where i change the OFS="_" and restore it to space when i find the -. It works... yet, i was curious if this is possible to solve using sed.
Thanks