Timeline for Print everything before nth delimiter
Current License: CC BY-SA 4.0
14 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Nov 16, 2023 at 12:51 | vote | accept | Smeterlink | ||
| Nov 16, 2023 at 12:33 | comment | added | Ed Morton |
Try any sed answer you get if the delimiter was ^, abc (or any other multi-char string), /, (or whatever is used to delimit the regexp in the script), or ' (or whatever is used to delimit the whole script), for example - they'll all fail in different ways given some of those "any other" delimiter values, no matter which sed version you use.
|
|
| Nov 16, 2023 at 12:15 | comment | added | Ed Morton | I haven't posted an answer dude because there is no answer to the question you asked and so far you haven't done what I suggested in my comment which is to reduce the scope of your question. GNU and BSD sed aren't "any version of sed" and "a letter like e or a number" aren't "any other" delimiter. If you want a solution that'll work in GNU or BSD sed with any single letter or number as a delimiter then say THAT in your question as there obviously is a solution for THAT scope, but not for "The delimiter in this example is \ but could be for any other. Should work with any version of sed.". | |
| Nov 16, 2023 at 6:53 | comment | added | Smeterlink |
@EdMorton the solution provided by "don_crissti" works perfectly with both GNU sed and BSD sed: sed -E 's/(^([^\]*[\]){3}[^\]*).*/\1/' infile. You can replace "\" with a letter like "e" or a number and keeps running: sed -E 's/(^([^e]*[e]){3}[^e]*).*/\1/' infile. So you are not willing to put the effort to elaborate your answer dude.
|
|
| Nov 15, 2023 at 22:06 | review | Close votes | |||
| Nov 20, 2023 at 3:01 | |||||
| Nov 15, 2023 at 21:55 | comment | added | Ed Morton | Regarding "The delimiter in this example is \ but could be for any other. Should work with any version of sed." - There are no possible solutions that would work for any delimiter in any version of sed. Reduce the scope of your question and provide sample input and expected output if you'd like a solution that works portably for your actual needs. | |
| Nov 15, 2023 at 13:31 | comment | added | Smeterlink | @terdon the delimiter is clearly the backslash as the link shows, but could use any other. Unless stated, should work with any version of sed. | |
| Nov 15, 2023 at 13:30 | history | edited | Smeterlink | CC BY-SA 4.0 |
added 68 characters in body
|
| Nov 15, 2023 at 13:02 | comment | added | terdon♦ |
Please edit your question and i) tell us your operating system or at least which sed implementation you are using, ii) show us an example input file and iii) the output you expect. We cannot help you parse data you don't show. You mention a delimiter, what is that delimiter? Should we guess you have `` as the delmiter?
|
|
| Nov 14, 2023 at 23:52 | answer | added | jhnc | timeline score: 2 | |
| Nov 14, 2023 at 20:10 | answer | added | Stéphane Chazelas | timeline score: 2 | |
| Nov 14, 2023 at 19:56 | answer | added | Prabhjot Singh | timeline score: 2 | |
| Nov 14, 2023 at 19:41 | answer | added | don_crissti | timeline score: 5 | |
| Nov 14, 2023 at 19:24 | history | asked | Smeterlink | CC BY-SA 4.0 |