Linux 如何在bash中阻止文本文件的排序行?

Linux 如何在bash中阻止文本文件的排序行?,linux,bash,sorting,Linux,Bash,Sorting,我有一个条形分隔的文本文件,如下所示: stringC|rest-of-lineC3 stringC|rest-of-lineC1 stringC|rest-of-lineC2 stringA|rest-of-lineA2 stringA|rest-of-lineA1 stringB|rest-of-lineB4 stringB|rest-of-lineB1 stringB|rest-of-lineB3 stringB|rest-of-lineB2 stringC|rest-of-lineC3

我有一个条形分隔的文本文件,如下所示:

stringC|rest-of-lineC3
stringC|rest-of-lineC1
stringC|rest-of-lineC2
stringA|rest-of-lineA2
stringA|rest-of-lineA1
stringB|rest-of-lineB4
stringB|rest-of-lineB1
stringB|rest-of-lineB3
stringB|rest-of-lineB2
stringC|rest-of-lineC3
stringA|rest-of-lineA2
stringC|rest-of-lineC1
stringA|rest-of-lineA1
stringB|rest-of-lineB4
stringB|rest-of-lineB1
stringC|rest-of-lineC2
stringB|rest-of-lineB3
stringB|rest-of-lineB2
我需要按
|
前面的字符串对其进行块排序,而不进行条后面的二次排序。因此,下面的示例应分为:

stringA|rest-of-lineA2
stringA|rest-of-lineA1
stringB|rest-of-lineB4
stringB|rest-of-lineB1
stringB|rest-of-lineB3
stringB|rest-of-lineB2
stringC|rest-of-lineC3
stringC|rest-of-lineC1
stringC|rest-of-lineC2
但不包括:

stringA|rest-of-lineA1
stringA|rest-of-lineA2
stringB|rest-of-lineB1
...
在bash脚本中是否有使用
sort
或任何其他命令来执行此操作的方法

如果原始文件不在块中,即它看起来像这样,如何获得与上述相同的结果:

stringC|rest-of-lineC3
stringC|rest-of-lineC1
stringC|rest-of-lineC2
stringA|rest-of-lineA2
stringA|rest-of-lineA1
stringB|rest-of-lineB4
stringB|rest-of-lineB1
stringB|rest-of-lineB3
stringB|rest-of-lineB2
stringC|rest-of-lineC3
stringA|rest-of-lineA2
stringC|rest-of-lineC1
stringA|rest-of-lineA1
stringB|rest-of-lineB4
stringB|rest-of-lineB1
stringC|rest-of-lineC2
stringB|rest-of-lineB3
stringB|rest-of-lineB2

使用
-s
选项进行排序,以获得稳定的

sort -st'|' -k1,1 file

初始块不重要,应该对两者都有效。

使用
-s
选项进行排序,以获得稳定的

sort -st'|' -k1,1 file
初始块不重要,应该对两者都有效