I would repeat some of what the other answers said,
and add some points that they missed.
The question was explicitly about sed
and/or awk
, etc…
You point out that the question was tagged text-processing.
What you seem not to have noticed was that the OP didn’t use that tag;
it got edited in four hours after the question was asked, by another person.
So you can’t really use the presence of the tag to justify your claim that
the OP didn’t really want to restrict the answers to use sed
or awk
.
But, on the other hand, I don’t believe that it’s reasonable
to expect every potential answerer to read the revision history
and try to figure out what the OP wants and what he doesn’t.
Many questions, as posted, are incomprehensible nonsense,
and therefore we allow other people
(who may understand the underlying technology, and/or know English,
better than the OP) to improve them.
You shouldn’t have to sift through chaotic previous versions of the question.
You should be able to answer the question, in its state at the time,
and have your answer judged with reference to that version of the question,
and not some past or future version.
Side note:
The person who added the text-processing tag to the question
also posted an answer not using sed
or awk
.
One way to look at the narrative is that this person
- found a question that was completely and exhaustively answered,
- edited the question to make it slightly broader, and then
- posted an answer that would have been out of scope for the original answer,
but was (arguably) in scope for the revised answer.
and it might be reasonable to ask whether that was appropriate behavior.
Other points:
- You point to the text-processing tag and claim
“all Linux distributions
has have python pre-installed”
to justify posting an answer using a tool other than what was asked for.
But, even if you interpret the question broadly,
it’s hard to deny that it’s looking for a command-line answer.
All the other answers present a command that can be typed into a shell,
and either hooked up to a pipe or given a filename parameter.
Yours doesn’t; it presents a Python program.
Sure, it’s just a matter of typing
python -c 'your_answer'
(or maybe python3 -c …
)
But
- you left out that part, which a beginner might not be able to figure out, and
- it’s not that simple,
because your answer uses both single quotes (
'
) and double quotes ("
),
so it can’t just be enclosed in quotes.
To add insult to injury, I was able to change your code, end = ""
,
to end = ''
, and it worked,
so your use of both kinds of quotes was an unnecessary complication.
(I don’t know Python, so I don’t know
whether you were following generally recognized good programming style,
or just being arbitrary.)
- The question says, “I have a bunch of output going through sed and awk.”
It does not say, “I have a file …” All the other answers
present a command that can take input from a pipe (or a file).
Your answer, as written, works only on a named file.
Again, I’m sure it’s trivial to change the Python code
to read from the standard input, but you didn’t do it.
OK, that said, I believe that your answer doesn’t deserve downvotes.
But those are some of the reasons why I didn’t upvote it.
Disclaimer: I am the author of one of the other answers to the question.