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 に答える