記事のディレクトリ
しかし
第三に、スペースを確保
- H / Hホールド、保持空間にH(追加のH)を覆うパターンスペースの内容
- G / G GET、パターンスペースにコンテンツ保持空間G(追記G)をカバー
- X交換、二つの空間の内容をスワップ
- 例えば
- マルチラインの使用、行のスプライシング
[root@localhost tmp]#sed 'H;${x;s/\n/,/g;s/^,//};$!d' test
- ライン反転出力
[root@localhost tmp]#sed '1!G;h;$!d' test22
[root@localhost tmp]#sed -n '1!G;h;$p' test22
理解
第四には、流れを変えます
- デフォルトのワークフロー(開始から終了までスクリプトの実行を)変更するのsed
ブランチ
無条件ジャンプ
使い方
[アドレス] B [ラベル]
ラベル定義
:LABEL
例については
test0311ファイルの内容
This is the 0 header line.
This is the 100 first data line.
This is the 200 second data line.
This is the 300 last data line.
無条件ジャンプ
[root@localhost tmp]#sed '2,3b;s/This is/Is this/;s/line./test?/' test0311
無条件ジャンプがタグ付けされました
[root@localhost tmp]#sed '/first/b jump1;s/This is/Is this/;:jump1;s/line./test?/' test0311
条件付きジャンプ
[root@localhost tmp]#echo "This, is , a, test, to, remove, coomas." | sed ':start;s/,//;t start'
- テスト
指定されたラベルへの条件ジャンプ
第五に、代替モード
- &
&コンテンツを定期的に試合に交換してください
例
[root@localhost tmp]#sed -r 's/[0-9]+/&s/g' test0311
- \ 1(後方参照)
例
[root@localhost tmp]#sed -r 's/(^.*)(\b[0-9]+\b )(.*$)/\2\1\3/g' test0311
[root@localhost tmp]#echo "abc 123 def" | sed -r 's/(^.*)(\b[0-9]+ \b)(.*$)/\2\1\3/g'
123 abc def
処理済みとして六、データの二行のN行をsedの
1. 1行にまとめ二行で、その結果、ストリングの改行から削除しました
[root@localhost tmp]#sed '/first/{ N; s/\n/ /}' test
文字を交換して2
[root@localhost tmp]#sed 'N ; s/this is/Is this/ ' test