广联达4.0升5.0:sed用法介绍 - Stephen,Yang - JavaEye技术网站
来源:百度文库 编辑:中财网 时间:2024/04/27 20:17:59
输出第1行到第3行
Shell代码
输出第2行
Shell代码
查找含有tomotoboy的行让后输出
Shell代码
输出当前的所有用户
Shell代码
输出第一行到含有字符串tomotoboy的行
Shell代码
输出原文的同时,输出tomotoboy所在的行号
Shell代码
输出含有tomotoboy的行的行号
Shell代码
输出第一行到最后一行
Shell代码
输出最后一行
Shell代码
append.sed:sed脚本实现附加功能,将hello tomotoboy附件在tomotoboy所在行之后
Shell代码
文本输出时,把tomotoboy替换成hello
Shell代码
只输出被替换的行
Shell代码
如果要附加或修改一个字符串,可以使用(&)命令,&命令保存发现模式以便重新调用它,然后把它放在替换字符串里面。
Shell代码
Shell代码
看看我们写好了哪些sed脚本
Shell代码
看看change.sed的用途是什么?
Shell代码
找到tomotoboy,替换为I love China,Ilove Wanzhi.
Shell代码
Shell代码
- -bash-3.00$ sed -n '1,3p' sed.txt
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- wangmin803 pts/16 Jul 29 14:18 (219.149.138.142)
- majorchan pts/21 Jul 29 15:18 (202.203.137.236)
-bash-3.00$ sed -n '1,3p' sed.txtliuzk423 pts/6 Jul 20 08:27 (219.245.104.240)wangmin803 pts/16 Jul 29 14:18 (219.149.138.142)majorchan pts/21 Jul 29 15:18 (202.203.137.236)
输出第2行
Shell代码
- -bash-3.00$ sed -n '2p' sed.txt
- wangmin803 pts/16 Jul 29 14:18 (219.149.138.142)
-bash-3.00$ sed -n '2p' sed.txtwangmin803 pts/16 Jul 29 14:18 (219.149.138.142)
查找含有tomotoboy的行让后输出
Shell代码
- -bash-3.00$ sed -n '/tomotoboy/'p sed.txt
- tomotoboy pts/45 Jul 29 13:53 (219.221.99.155)
- tomotoboy pts/46 Jul 29 15:24 (219.221.99.155)
- tomotoboy pts/52 Jul 29 16:20 (219.221.99.155)
-bash-3.00$ sed -n '/tomotoboy/'p sed.txttomotoboy pts/45 Jul 29 13:53 (219.221.99.155)tomotoboy pts/46 Jul 29 15:24 (219.221.99.155)tomotoboy pts/52 Jul 29 16:20 (219.221.99.155)
输出当前的所有用户
Shell代码
- /home/l/g/tomotoboy >who
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >wholiuzk423 pts/6 Jul 20 08:27 (219.245.104.240)tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)guise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
输出第一行到含有字符串tomotoboy的行
Shell代码
- /home/l/g/tomotoboy >who | sed -n '1,/tomotoboy/'p
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
/home/l/g/tomotoboy >who | sed -n '1,/tomotoboy/'pliuzk423 pts/6 Jul 20 08:27 (219.245.104.240)tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
输出原文的同时,输出tomotoboy所在的行号
Shell代码
- -/home/l/g/tomotoboy >who|sed '/tomotoboy/'=
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- 2
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
-/home/l/g/tomotoboy >who|sed '/tomotoboy/'=liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)2tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)guise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
输出含有tomotoboy的行的行号
Shell代码
- /home/l/g/tomotoboy >who | sed -e '/tomotoboy/'=
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- 2
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- kindy pts/38 Aug 7 21:33 (reverse.gdsz.cncnet.net)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >who | sed -e '/tomotoboy/'=liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)2tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)guise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)kindy pts/38 Aug 7 21:33 (reverse.gdsz.cncnet.net)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
输出第一行到最后一行
Shell代码
- /home/l/g/tomotoboy >who | sed -n '1,$p'
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >who | sed -n '1,$p'liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)guise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
输出最后一行
Shell代码
- /home/l/g/tomotoboy >who|sed -n '$p'
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >who|sed -n '$p'yagamil pts/46 Aug 7 20:48 (199.40.206.191)
append.sed:sed脚本实现附加功能,将hello tomotoboy附件在tomotoboy所在行之后
Shell代码
- /home/l/g/tomotoboy >cat append.sed
- #!/bin/sed -f
- /tomotoboy/ a\
- hello tomotoboy
- /home/l/g/tomotoboy >who| append.sed
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- hello tomotoboy
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- kindy pts/38 Aug 7 21:41 (reverse.gdsz.cncnet.net)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >cat append.sed#!/bin/sed -f/tomotoboy/ ahello tomotoboy/home/l/g/tomotoboy >who| append.sedliuzk423 pts/6 Jul 20 08:27 (219.245.104.240)tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)hello tomotoboyguise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)kindy pts/38 Aug 7 21:41 (reverse.gdsz.cncnet.net)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
文本输出时,把tomotoboy替换成hello
Shell代码
- /home/l/g/tomotoboy >who|sed 's/tomotoboy/hello/'
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- hello pts/16 Aug 7 21:24 (219.221.98.71)
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
/home/l/g/tomotoboy >who|sed 's/tomotoboy/hello/'liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)hello pts/16 Aug 7 21:24 (219.221.98.71)guise pts/21 Aug 7 17:56 (124.76.10.207)guise pts/35 Aug 7 21:13 (58.41.162.27)yagamil pts/46 Aug 7 20:48 (199.40.206.191)
只输出被替换的行
Shell代码
- /home/l/g/tomotoboy >who|sed -n 's/tomotoboy/hello/p'
- hello pts/16 Aug 7 21:24 (219.221.98.71)
/home/l/g/tomotoboy >who|sed -n 's/tomotoboy/hello/p'hello pts/16 Aug 7 21:24 (219.221.98.71)
如果要附加或修改一个字符串,可以使用(&)命令,&命令保存发现模式以便重新调用它,然后把它放在替换字符串里面。
Shell代码
- /home/l/g/tomotoboy >who|sed -n 's/tomotoboy/hello &/p'
- hello tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)
- /home/l/g/tomotoboy >who|sed -n 's/tomotoboy/& my friend/p'
- tomotoboy my friend pts/16 Aug 7 21:24 (219.221.98.71)
/home/l/g/tomotoboy >who|sed -n 's/tomotoboy/hello &/p'hello tomotoboy pts/16 Aug 7 21:24 (219.221.98.71)/home/l/g/tomotoboy >who|sed -n 's/tomotoboy/& my friend/p'tomotoboy my friend pts/16 Aug 7 21:24 (219.221.98.71)
Shell代码
- 删除最后一行
- bash-3.00$ sed '$d' sed.txt
- 删除第一到最后6行
- -bash-3.00$ sed '1,6d' sed.txt
- 删除第一到最后一行
- -bash-3.00$ sed '1,$d' sed.txt
- 删除tomotoboy的行
- -bash-3.00$ sed '/tomotoboy/d' sed.txt
- 用seawolf替代tomotoboy
- -bash-3.00$ sed 's/tomotoboy/seawolf/' sed.txt
- 用seawolf替代tomotoboy然后输出到sed.out
- -bash-3.00$ sed 's/tomotoboy/seawolf/w sed.out' sed.txt
删除最后一行bash-3.00$ sed '$d' sed.txt删除第一到最后6行-bash-3.00$ sed '1,6d' sed.txt删除第一到最后一行-bash-3.00$ sed '1,$d' sed.txt删除tomotoboy的行-bash-3.00$ sed '/tomotoboy/d' sed.txt用seawolf替代tomotoboy-bash-3.00$ sed 's/tomotoboy/seawolf/' sed.txt用seawolf替代tomotoboy然后输出到sed.out-bash-3.00$ sed 's/tomotoboy/seawolf/w sed.out' sed.txt
看看我们写好了哪些sed脚本
Shell代码
- /home/l/g/tomotoboy >ls -al|grep 'sed$'
- -rwxr--r-- 1 tomotoboy member 45 Aug 7 21:41 append.sed
- -rwxr--r-- 1 tomotoboy member 68 Jul 30 16:28 change.sed
/home/l/g/tomotoboy >ls -al|grep 'sed$'-rwxr--r-- 1 tomotoboy member 45 Aug 7 21:41 append.sed-rwxr--r-- 1 tomotoboy member 68 Jul 30 16:28 change.sed
看看change.sed的用途是什么?
Shell代码
- /home/l/g/tomotoboy >cat change.sed
- #!/bin/sed -f
- #change.sed
- /tomotoboy/ c\
- I love China,Ilove Wanzhi.
/home/l/g/tomotoboy >cat change.sed#!/bin/sed -f#change.sed/tomotoboy/ cI love China,Ilove Wanzhi.
找到tomotoboy,替换为I love China,Ilove Wanzhi.
Shell代码
- /home/l/g/tomotoboy >who|change.sed
- liuzk423 pts/6 Jul 20 08:27 (219.245.104.240)
- I love China,Ilove Wanzhi.
- guise pts/21 Aug 7 17:56 (124.76.10.207)
- guise pts/35 Aug 7 21:13 (58.41.162.27)
- uyty pts/38 Aug 7 22:09 (p3213-ipbf803souka.saitama.ocn.ne.jp)
- yagamil pts/46 Aug 7 20:48 (199.40.206.191)
谁能介绍一下Stephen Bishop
帮我介绍一下用法
Stephen Hamking是谁
something about Stephen Hawking
Who is Stephen Hawking
stephen Leacock 是谁?
什麼是SED平板电视机
帮帮我,SED HT508
SED手机锁怎么办?
桑达SED手机锁
SED手机彩信下载
ya ya 学语是哪个 ya 呀?
谁知道这首英文歌YA YA YA
Stephen Grately的官方网站是?
谁知道Stephen最近在干嘛?
ya ya 小猪 大猪头!
Hi ya ya 夏日 mp3
介绍虚拟光驱的用法和具体操作?谢谢
请介绍CopyLock1.09的用法
请介绍一下imageready的用法
糖量计的用法和介绍
哪位姐姐 介绍一下 发夹的用法?
请介绍下until的用法。
SED是什么手机的牌子