Skip to main content
added 141 characters in body
Source Link
Digital Trauma
  • 8.9k
  • 2
  • 25
  • 42

If you have the rs utility installed, you can do this:

rs -c' ' -T | {
    read
   stdbuf printf-i0 "%s\n"sed "$REPLY""1q"
    sort -V
} | rs -C' ' -T

Or all on one line:

rs -c' ' -T | { read ;stdbuf printf-i0 "%s\n"sed "$REPLY";"1q"; sort -V ; } | rs -C' ' -T
  • The first rs transposes the input data (with space-sparated fields)
  • The command group:
    • readseds reads the first line, outputs it, then quits, leaving the rest of the pipe from (the header)
    • printfrss it back untouched. stdbuf is required to ensure that sed only reads up to the first newline and no further, by turning off input buffering
    • sorts the remaining lines
  • The second rs transposes the resulting stream back to its original format.

rs is installed by default on MacOS. On Linux systems you may have to install it - e.g.

sudo apt install rs

Caveat: stdbuf and sorts -V option are GNU-specific so won't work on unmodified MacOS.

If you have the rs utility installed, you can do this:

rs -c' ' -T | {
    read
    printf "%s\n" "$REPLY"
    sort -V
} | rs -C' ' -T

Or all on one line:

rs -c' ' -T | { read ; printf "%s\n" "$REPLY"; sort -V ; } | rs -C' ' -T
  • The first rs transposes the input data (with space-sparated fields)
  • The command group:
    • reads the first line (the header)
    • printfs it back
    • sorts the remaining lines
  • The second rs transposes the resulting stream back to its original format.

rs is installed by default on MacOS. On Linux systems you may have to install it - e.g.

sudo apt install rs

If you have the rs utility installed, you can do this:

rs -c' ' -T | {
    stdbuf -i0 sed "1q"
    sort -V
} | rs -C' ' -T

Or all on one line:

rs -c' ' -T | { stdbuf -i0 sed "1q"; sort -V ; } | rs -C' ' -T
  • The first rs transposes the input data (with space-sparated fields)
  • The command group:
    • sed reads the first line, outputs it, then quits, leaving the rest of the pipe from rs untouched. stdbuf is required to ensure that sed only reads up to the first newline and no further, by turning off input buffering
    • sorts the remaining lines
  • The second rs transposes the resulting stream back to its original format.

rs is installed by default on MacOS. On Linux systems you may have to install it - e.g.

sudo apt install rs

Caveat: stdbuf and sorts -V option are GNU-specific so won't work on unmodified MacOS.

Source Link
Digital Trauma
  • 8.9k
  • 2
  • 25
  • 42

If you have the rs utility installed, you can do this:

rs -c' ' -T | {
    read
    printf "%s\n" "$REPLY"
    sort -V
} | rs -C' ' -T

Or all on one line:

rs -c' ' -T | { read ; printf "%s\n" "$REPLY"; sort -V ; } | rs -C' ' -T
  • The first rs transposes the input data (with space-sparated fields)
  • The command group:
    • reads the first line (the header)
    • printfs it back
    • sorts the remaining lines
  • The second rs transposes the resulting stream back to its original format.

rs is installed by default on MacOS. On Linux systems you may have to install it - e.g.

sudo apt install rs