-   Programming (
-   -   Sed replace string problem. (

zcrxsir88 02-11-2009 11:03 AM

Sed replace string problem.
Greetings all,

I'm having some trouble figuring out how to do replace a single character in some output I'm working with. I'm pretty sure sed will take care of it for me, but I haven't quite figured it out.

The data looks as such.,>,,UDP,>,,UDP,>,,UDP,>,,UDP,>,,UDP

But I need it to look like this.,>,,UDP,>,,UDP,>,,UDP,>,,UDP,>,,UDP

If anyone could help I would greatly appreciate it!



colucix 02-11-2009 11:39 AM


sed -i.bck 's/\(.*\)[.]\([0-9]*,.*\)$/\1:\2/g' file
the regular expression matches any string .* plus a literal dot [.] plus any number [0-9]* followed by a comma plus any string to the end of the line ,.*$

zcrxsir88 02-11-2009 12:04 PM


Thank you for the quick reply. Everything works great. I did notice that I have to run the string multiple times to get both the :'s in there. Which is completely not a big deal, I was just curious if there was a way to make them do both at the same time?

Thanks again!


colucix 02-11-2009 12:10 PM

Ops... I didn't notice the first one. Here is another command

sed -i.bck 's/\(.*\)[.]\([0-9]*,>,.*\)[.]\([0-9]*,.*\)$/\1:\2:\3/g' file

zcrxsir88 02-11-2009 12:48 PM

Thanks again! I figured it was something like that but couldn't get it to work properly.

Thank you!


All times are GMT -5. The time now is 10:21 AM.