Timeline for Cut and replace Nth character on every row
Current License: CC BY-SA 4.0
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 26, 2024 at 23:54 | vote | accept | XJMZX | ||
| Jun 26, 2024 at 23:54 | comment | added | XJMZX | I accept this as not only the simplest solution, but also this is the answer I wanted. Specifically, the simplest method to explicitly replace a character in a certain position in a predictable pattern. Thanks again. | |
| Jun 26, 2024 at 20:36 | history | edited | terdon♦ | CC BY-SA 4.0 |
deleted 11 characters in body
|
| Jun 26, 2024 at 13:36 | comment | added | XJMZX | 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. | |
| Jun 26, 2024 at 13:28 | comment | added | terdon♦ |
@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.
|
|
| Jun 26, 2024 at 13:24 | comment | added | terdon♦ |
@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 .
|
|
| Jun 26, 2024 at 13:23 | comment | added | XJMZX |
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,
|
|
| Jun 26, 2024 at 13:23 | comment | added | XJMZX |
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 ,
|
|
| Jun 26, 2024 at 13:13 | history | edited | terdon♦ | CC BY-SA 4.0 |
added 1 character in body
|
| Jun 26, 2024 at 12:46 | history | answered | terdon♦ | CC BY-SA 4.0 |