Skip to main content
added 424 characters in body
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 56

The sort command can only sort input records delimited by newline or NUL character as indicated in the manual

The sort utility sorts text and binary files by lines. A line is a record separated from the subsequent record by a newline (default) or NUL '\0' character

So your transformation at some point would need to know the knowledge of record delimiter (in your case |) to arrive at the desired result. Any other commands (Awk/Perl or datamash) would need to make this assumption


Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -

Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -

The sort command can only sort input records delimited by newline or NUL character as indicated in the manual

The sort utility sorts text and binary files by lines. A line is a record separated from the subsequent record by a newline (default) or NUL '\0' character

So your transformation at some point would need to know the knowledge of record delimiter (in your case |) to arrive at the desired result. Any other commands (Awk/Perl or datamash) would need to make this assumption


Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -
deleted 3 characters in body
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 56

Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr -s '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -

Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr -s '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -

Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -
Source Link
Inian
  • 13.1k
  • 2
  • 42
  • 56

Not with a single standalone tool, but with tr, sort and paste you could do. You could see how the transformation taking shape, by adding one command at a time to the pipeline

echo 'a;b;f|d;e;c|g;h' | tr -s '|' '\n' | sort -t';' -k3,3 | paste -sd'|' -