目次~
#contents

*文字操作 [#n81223ce]
-[[文字列の削除]]
 sed -e "s/TexttoRemove//g"

行頭の文字列を消す
 sed -e "s/^TexttoRemove//"

行末の文字列を消す
 sed -e "s/TexttoRemove\$//"

Patternを含む行を削除する
 sed -e "s/Pattern.*//"

タブをスペースに変換
**変換 [#r09aacde]
-タブをスペースに変換
 sed -e 's///g

複数のスペースを1個スペースに変換
-複数のスペースを1個スペースに変換
 sed -e '*//g'

行頭のホワイトスペースを削除する
**削除 [#a2ee30da]
-空白行を削除
 sed -e '/^$/d'

-行頭のホワイトスペースを削除する
 sed -e 's/^[]*//'

行末のホワイトスペースを削除
-行末のホワイトスペースを削除
 sed -e "s/[]*\$//"

Textという文字列を含んだ行を削除する
-Textという文字列を含んだ行を削除する
 sed -e "/Text/d"

空白行を削除
 sed -e '/^$/d'
-文字列の削除
 sed -e "s/TexttoRemove//g"

-行頭の文字列を消す
 sed -e "s/^TexttoRemove//"

-行末の文字列を消す
 sed -e "s/TexttoRemove\$//"

-Patternを含む行を削除する
 sed -e "s/Pattern.*//"


*処理範囲の指定 [#o2776d0a]
5行目から3行目を処理
 sed -e "5,20s/OldText/NewText/g" file

5行目から最後までを処理
 sed -e "5,$s/OldText/NewText/g" file

1行目を削除
 sed -e '1d' file

1行目から1行目を削除
 sed -e '1,4d' file

最終行を削除
 sed -e '$d' file

最終4行を削除
 sed -e '$-3,$d' file

*実用Tips [#y26d620e]

nからmまでを表示
 sed -n 'n,mp' file

配下のディレクトリを表示
 ls -l|grep ^[d].*|awk '{print $9}'~

サンプルファイルの中のOldTextをNewTextに変換してresultに書き出す
 sed -e "s/OldText/NewText/g" samplefile >result

ユーザーIDをUSERに代入
 USER=`id |sed 's/uid=.*(\(.*\)) gid=.*/\1/'`

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS