|
|
|
|
|
by mandelbulb
2942 days ago
|
|
>This really only becomes obvious when you pass the -p flag, where the program information is printed on its own line. It isn't on its own line, it's just wrapped so grep works properly. >but the column spacing is incorrect instead. ss output is column-based so it is useless to bother with tools like cat for parsing. ss -p | less -S is the simplest solution for you |
|
First: Apparently the ss developer(s) decided to finally fix the output in some recent version (it was changed to behave sanely somewhere between iproute2-ss161212 and iproute2-ss180402).
However, if you're stuck with an older version, what I said still stands, and the below applies to those versions:
> It isn't on its own line, it's just wrapped so grep works properly.
While technically correct, that doesn't really matter in any practical sense, because the columns are padded so that the final column containing the program is wrapped onto the next line.
When ss stdout is connected to a pipe it will produce different output: this output is much less wide, so that the program name fits onto the same line as the rest of the columns. But, as said previously, it screws up the alignment of the columns, making it impossible to quickly scan them (using your eyes).
> ss output is column-based so it is useless to bother with tools like cat for parsing.
What? cat doesn't do any parsing. The only reason for using cat there is to connect ss' stdout to a pipe and thus trigger its different output.
> ss -p | less -S is the simplest solution for you
No. '| less -S' gives no improvement over '| cat', since ss output fits onto one line without wrapping as soon as you pipe it through any other program. An actual improvement would be to instead use '| column -t', which would (mostly) fix issues with misaligned columns.
Anyway, if you can, just use a modern enough ss instead (not sure when it was fixed, but iproute2-ss180402 (iproute2 4.16.0) is definitely new enough), which has sane output regardless of whether stdout is connected to a pipe or terminal.