6

I posted this question which has garnered two down votes over two days (and counting): sort | uniq remove the counts that occur most often

Unfortunately it's too late to delete it as it has a good answer.

This could be an opportunity for self improvement and avoid the same pitfalls with future questions and/or improving this question for redemption.

The down-voters didn't leave comments as is often the case so, perhaps others can help point out the flaws in my question?

Thank you for taking the time out of your busy day the world gives most of us. Hopefully others can learn from your comments / answers too :)

6
  • 3
    I don't see anything to elaborate on because the question looks OK to me.
    – karel
    Sep 6, 2018 at 4:42
  • 2
    Looks good to me too. It may be this or people (not me !!!) who believe Ubuntu users should not ask coding questions.
    – Takkat
    Sep 6, 2018 at 6:31
  • 1
    I agree, it looks like a programming question but we do support the shell and interacting with it, so, as your question is about bash, it is on topic. See: meta.askubuntu.com/questions/13807/…
    – Mark Kirby
    Sep 6, 2018 at 9:22
  • 4
    Your question would be improved if you added an example output so we know what you would like to see. Also, the 'TL;DR' seems to be the exact opposite: it is much longer than the actual question and not a summary. Frankly, after reading your question three times, I still don't understand what you are asking for.
    – terdon
    Sep 6, 2018 at 11:32
  • @terdon I added the desired output. The gist of it capturing Process ID's running over a period of 6 to 10 seconds. Sampling 10 to 25 times per second. Then stripping out all those processes that were running the whole time. Leaving you with a short list of suspects. Sep 6, 2018 at 22:34
  • @Takkat When I first joined the site I noticed programming questions were off-topic and had to go to Stack Overflow. However we see bash, process ID (PID), sed, sort, grep, awk and uniq questions here all the time. So unless it's the issue of discovering what programs are running when, I don't think it's off-topic based on programming. For that it would be specific questions about C code or something similar I think. Sep 8, 2018 at 0:08

1 Answer 1

6

What follows is my personal opinion; votes will show whether others agree or not. I like to be outspoken and clear which is sometimes misunderstood as being rude and hostile. Please bear with me; in no way do I intend to offend anybody.

Your question is unclear and thus unlikely to help others. Only with the help of the answer am I able to guess what you’re asking for. Here’s what I think you’re actually asking:

I have a text file with multiple lines whose first (whitespace-separated) column contains an integer. I want to remove every line with

  • the most occuring integer in this column and
  • any integer greater than this most occuring one.

How can I do that?

Example input

  1 /mnt/e/bin/ps-suspects.sh Possible suspects causing problems
 11 1 S root       128     2  0  60 -20 -     0 -      03:27 ?
 11 4 Z root     19087  7064  0  80   0 -     0 -      03:32 ?
 11 1 S root        75     2  0  60 -20 -     0 -      03:27 ?
  3 1 S root       469     2  0  60 -20 -     0 -      03:27 ?
  3 1 S root       468     2  0  60 -20 -     0 -      03:27 ?
 22 0 S rick     17058  2859  0  80   0 -  7413 wait   16:56 pts/2

Here, 11 occurs most often and 22 is greater than 11, so every line containing 11 or 22 in the first column needs to be removed.

Example output

  1 /mnt/e/bin/ps-suspects.sh Possible suspects causing problems
  3 1 S root       469     2  0  60 -20 -     0 -      03:27 ?
  3 1 S root       468     2  0  60 -20 -     0 -      03:27 ?

This should be the question and seems to be the only part that’s relevant and possibly helpful to others. If you really feel like this could be an XY problem (and only then) you can include further information on why you need this, but:

  • keep it clearly separated from the actual question (= “tl;dr” section), connected by footnote marks at most
  • from the beginning, explain clearly where you’re coming from, what you want to achieve in the end and where you’re stuck
  • (you certainly know what you’re doing, so) cut code and terminal output to only include relevant and non-redundant information
    The echo lines from your script are nothing but noise in the context of your question, and the post contains them twice.

Not nearly as important as what’s said above, but still worth mentioning: Add tags according to their description, not because the tag name happens to be mentioned in your post. Your question is about rather than or .

5
  • I've never thought you of all people rude or hostile.The "TL;DR" section contains the answer which wasn't posted as an answer to not detract from ByteCommander's answer. Even though the awk solution does solve the question, the guilty process (PID) was already running making the question futile. When posted, sort and uniq were in the title and became tags. In hindsight the title should have been "How to find which processes started and ended over a snapshot of real time?" Normally I would just delete the question that wouldn't interest others but I can't because it's been answered. Sep 7, 2018 at 23:59
  • I totally agree the question is long-winded and contains TMI but that is a pit-fall of writing a succinct question whilst the mind is in the middle of a programming quagmire of new commands and foreign architecture OS. As mentioned earlier, normally I would delete the question that wouldn't interest others after solving the problem the same night. Thanks for taking the time to analyze the question :) Sep 8, 2018 at 0:02
  • 2
    @WinEunuuchs2Unix If it’s an anwer, please post it as one – keeping questions and answers separated is crucial! As you accepted ByteCommander’s answer, it will stay on top anyway. There’s also nothing wrong in (even drastically!) changing a question and adapting it to a good answer. Make it relevant to others.
    – dessert
    Sep 8, 2018 at 7:05
  • Using most of your suggestions I've edited the question and added an answer. It's still not perfect but, I hope it's substantially improved. Sep 9, 2018 at 17:16
  • 1
    Thanks in large part to your answer and comments, the question has gone from -3 at one point to +2 today. Even the answer you suggested to post has got an up-vote. Thank you :) Sep 10, 2018 at 22:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .