Devon
Devon

Reputation: 335

How can use SED to replace a space with a comma

I've been trying to get this to work with no luck.. I have two values in my script. Right now it has a space, I want to place a comma in-between them.

sed -e 's/.*-Xmx16000m //g'

Please let me know what I'm missing.

Upvotes: 0

Views: 89

Answers (1)

Chris Dodd
Chris Dodd

Reputation: 126536

Your question is not very clear, but I'm guessing you might want something like

sed -e 's/\(-Xmx16000m\) /\1,/g'

This will look for the string -Xmx1600m followed by a space, and will replace the following space with a comma. There doesn't need to be anything in particular after it. Alterantely, you might want

sed -e 's/\(pattern1\) \(pattern2\)/\1,\2/g'

which will seach for pattern1 and pattern2 separated by a space (these patterns might be any regexp, not just fixed strings), and replace the space between them with a comma.

Upvotes: 1

Related Questions