sed -e 's#/#-#g' -e's#:#-#g' passwd
vim 123.sed s#:#/#g s#/#-#g
sed -f 123.sed passwd
sed -n 2p passwd
sed 's/in/AAAAA/2' passwd
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bAAAAA:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbAAAAA/nologin
注意:在每一行內第二次匹配到in,纔會替換成AAAAAexpress
sed '2s/in/AAAAA/2' passwd
root:x:0:0:root:/root:/bin/bash bin:x:1:1:bAAAAA:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbin/nologin
注意:能夠使用-n -p 組合vim
sed -n '2s/in/AAAAA/2p' passwd bin:x:1:1:bAAAAA:/bin:/sbin/nologin
sed -n '2,3s/in/AAAAA/2p' passwd
bin:x:1:1:bAAAAA:/bAAAAA:/sbin/nologin daemon:x:2:2:daemon:/sbin:/sbAAAAA/nologin
sed -n '2,$s/in/AAAAA/2p' passwd
注意:能夠使用$表示到結尾bash
sed -n '2s/in/AAAAA/2pw passwd.sed' passwd bin:x:1:1:bAAAAA:/bin:/sbin/nologin
cat passwd.sed
bin:x:1:1:bAAAAA:/bin:/sbin/nologin
sed -i.bak '2s/in/AAAAA/2' passwd
cat -n passwd
1 root:x:0:0:root:/root:/bin/bash 2 bin:x:1:1:bAAAAA:/bin:/sbin/nologin
ls passwd* passwd passwd.bak
sed -n '/root/s/bin/AAAAA/p' passwd
root:x:0:0:root:/root:/AAAAA/bash operator:x:11:0:operator:/root:/sAAAAA/nologin
9,sed多命令執行:spa
sed '1{ s/root/ROOT/ s/bin/BIN/ }' passwd
ROOT:x:0:0:root:/root:/BIN/bash
sed -n -e '1s/root/ROOT/' -e '1s/bin/BIN/' -e 1p passwd
ROOT:x:0:0:root:/root:/BIN/bash