假設一個文本文件包含應改變其順序的特定行。單詞(子字符串)由單個空格分隔。要改變的行可以通過它們的第一個字符(例如「>」)來標識。通過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