Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

6
  • Thanks. I'm stunned at how simple a soution that is. I don't understand why it just operates on the first occurance on each row, rather than finding and moifying each occurance of , Commented Jun 26, 2024 at 13:23
  • The second example also works as expected for my need, but I don't understand what the pattern .. and 10 do in terms of finding the 19th and 20th character, Commented Jun 26, 2024 at 13:23
  • 4
    @XJMZX because that's how the s/old/new/ substitution operator works. It would only replace all occurrences if you explicitly tell it do do so using g, like this: sed 's/, /x/g' file . Commented Jun 26, 2024 at 13:24
  • 2
    @XJMZX since the pattern is .., which is two characters long, the first match for .. would be the first two characters. Consider echo abcd | sed 's/../xx/2' which returns abxx. That is because the first occurrence of .. would be ab and the second is cd. In other words, the second pair of characters corresponds to characters 3 and 4, just lke the first pair would be 1 and 2. Similarly, the 10th pair of characters corresponds to the 19th and 20th character. Commented Jun 26, 2024 at 13:28
  • 1
    Thanks for the explanations. Makes sense now. I guess I was approaching this all wrong from not understanding how it works. Since this is the simplest solution, I'll mark this correct answer. Perhaps I should have wrote the question differently. My bad. Commented Jun 26, 2024 at 13:36