2

我真正想做的是使用sed. 我知道这可能会更容易使用其他东西,但不幸的是需要 sed (测试自己)

所以,例子是

One line here
Two line here as well
Third line could be here
fourth line to end

最终会成为

Two line here
One line here as well
fourth line could be here
third line to end

我可能一直在使用错误的操作,sed但是是的,不知道。任何线索?

4

2 回答 2

3
sed -e 'N; s/\([a-zA-Z]*\)\(.*\)\n\([a-zA-Z]*\)\(.*\)/\3\2\   ⏎
\1\4/'

(是的,这是一个显式的换行符,由替代中的反斜杠转义)

于 2012-05-01T12:25:21.250 回答
1

这可能对您有用(可能是 GNU sed):

sed '$!N;s/\(\S*\)\(.*\n\)\(\S*\)/\3\2\1/' file
Two line here
One line here as well
fourth line could be here
Third line to end
于 2012-05-01T15:59:29.893 回答