sedの使い方
をテンプレートにして作成
[
トップ
] [
新規
|
一覧
|
検索
|
最終更新
|
ヘルプ
]
開始行:
目次~
#contents
*文字操作 [#n81223ce]
**変換 [#r09aacde]
-タブをスペースに変換
sed -e 's///g
-複数のスペースを1個スペースに変換
sed -e '*//g'
**削除 [#a2ee30da]
-空白行を削除
sed -e '/^$/d'
-行頭のホワイトスペースを削除する
sed -e 's/^[]*//'
-行末のホワイトスペースを削除
sed -e "s/[]*\$//"
-Textという文字列を含んだ行を削除する
sed -e "/Text/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/'`
終了行:
目次~
#contents
*文字操作 [#n81223ce]
**変換 [#r09aacde]
-タブをスペースに変換
sed -e 's///g
-複数のスペースを1個スペースに変換
sed -e '*//g'
**削除 [#a2ee30da]
-空白行を削除
sed -e '/^$/d'
-行頭のホワイトスペースを削除する
sed -e 's/^[]*//'
-行末のホワイトスペースを削除
sed -e "s/[]*\$//"
-Textという文字列を含んだ行を削除する
sed -e "/Text/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/'`
ページ名: