LoginSignup
0
0

Linuxコマンド覚え書き / sed

Last updated at Posted at 2024-01-13

sed

連続置換

$ cat dbconn.pl | grep CONNECT_ORA
$CONNECT_ORA="scott/tiger"; 
# CONNECT_ORAの「先頭の$を削除」「文字列中の"を削除」「行末の;を削除」を一度に実行する.,
$ cat dbconn.pl | grep CONNECT_ORA | sed -e 's/^\$//g' -e 's/;$//g' -e 's/"//g'
CONNECT_ORA=scott/tiger

psコマンドでbashプロセスのpidを抽出する

$ ps -ef|grep bash|grep -v grep|sed -e "s/\s\+/ /"|cut -f 2 --delim=" "

echoコマンドとの組み合わせ

標準出力結果に"#"を先頭に追加する

$ echo aaa | sed -e "s/.*/# &/"
# aaa
$ echo aaa > aaa.txt
$ cat aaa.txt | sed -e "s/.*/# &/"
# aaa

行削除

パターンにマッチする行を削除して上書きする(-iオプション).
以下の場合は先頭が"#"で始まる行を削除する.

$ sed -i -e '/^#/d' a.txt
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0