假设一个文本文件包含应改变其顺序的特定行。单词(子字符串)由单个空格分隔。要改变的行可以通过它们的第一个字符(例如“>”)来标识。通过bash对子串进行内联重新排序
# cat test.txt
>3 test This is
foo bar baz
foo bar qux
>2 test This is
foo bar baz
>1 test This is
foo bar qux
什么命令(可能在awk
)你会使用跨开始的关键字符的所有行采用同样的订购过程?
# cat test.txt | sought_command
>This is test 3
foo bar baz
foo bar qux
>This is test 2
foo bar baz
>This is test 1
foo bar qux
不懂的排序规则.. .. – Kent
你有什么尝试?是否有一个更抽象的输入和输出定义,可以使重新排序规则更清晰? – l0b0