Linux Sed???????
?????ggjucheng ???????[ 2016/7/27 10:26:26 ] ?????????????? Linux ????
	???????
	????sed ??????????????????δ????????????????????????????д洢????????????У????“?????”??pattern space??????????sed????????????е???????????????????????????????????????????????У?????????????????????β????????????? ?????????????????洢?????Sed????????????????????????????????????????????д?????????
	????sed??ò???
	????[root@ wwww ~]# sed [-nefr] [????]
	??????????????
	????-n ????e???(silent)????????? sed ???÷??У????????? STDIN ????????????г?????????????????? -n ??????????о???sed ????????????(???????)????г?????
	????-e ???????????????????? sed ?????????
	????-f ?????? sed ?????д??????????? -f filename ????????? filename ??? sed ??????
	????-r ??sed ???????????????????????????????(??????????????????)
	????-i ???????????????????????????????????
	????????????? [n1[??n2]]function
	????n1?? n2 ?????????????????????????ж?????????????????????????????????????? 10 ?? 20 ???????е???? 10??20[???????] ??
	????function??
	????a ???????? a ??????????????????Щ????????μ???г???(?????????)??
	????c ??????? c ????????????????Щ?????????? n1??n2 ?????У?
	????d ??????????????????????? d ????????????κ??????
	????i ?????? i ??????????????????Щ????????μ???г???(?????????)??
	????p ?????????????????????????????? p ??????? sed -n ??????С?
	????s ??????????????????????????????????? s ?????????????????????????? 1??20s/old/new/g ??????
	???????????λ??????/???
	?????? /etc/passwd ???????г?????????к?????????? 2~5 ???????
	????[root@ wwww ~]# nl /etc/passwd | sed '2??5d'
	????1 root:x:0:0:root:/root:/bin/bash
	????6 sync:x:5:0:sync:/sbin:/bin/sync
	????7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
	????.....(???????).....
	????sed ?????? ‘2??5d’ ????? d ?????????? 2-5 ?и????????????????????????? 2-5 ????? ?????????£???????????′? sed -e ??????? -e ?????????????????? sed ?????????????????? ” ???????????????
	??????????? 2 ??
	????nl /etc/passwd | sed '2d'
	?????????? 3 ???????
	????nl /etc/passwd | sed '3??$d'
	?????????к?(????????????)?????drink tea?????????
	????[root@ wwww ~]# nl /etc/passwd | sed '2a drink tea'
	????1 root:x:0:0:root:/root:/bin/bash
	????2 bin:x:1:1:bin:/bin:/sbin/nologin
	????drink tea
	????3 daemon:x:2:2:daemon:/sbin:/sbin/nologin
	????.....(???????).....
	???????????????????
	????nl /etc/passwd | sed '2i drink tea'
	????????????????????????????к????????????????硺Drink tea or …..????drink beer???
	????[root@ www ~]# nl /etc/passwd | sed '2a Drink tea or ......
	????> drink beer ?'
	????root:x:0:0:root:/root:/bin/bash
	????bin:x:1:1:bin:/bin:/sbin/nologin
	????Drink tea or ......
	????drink beer ?
	????daemon:x:2:2:daemon:/sbin:/sbin/nologin
	????.....(???????).....
	???????????????????б??? ???????????е?????????????????????У????????????????е??????  ?????
	???????????λ???滻?????
	????????2-5?е?????????????No 2-5 number?????
	????[root@ wwww ~]# nl /etc/passwd | sed '2??5c No 2-5 number'
	????1 root:x:0:0:root:/root:/bin/bash
	????No 2-5 number
	????6 sync:x:5:0:sync:/sbin:/bin/sync
	????.....(???????).....
	?????????????????????????????????????
	???????г? /etc/passwd ??????? 5-7 ??
	????[root@ wwww ~]# nl /etc/passwd | sed -n '5??7p'
	????5 lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
	????6 sync:x:5:0:sync:/sbin:/bin/sync
	????7 shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
	?????????????? sed ?????????λ?????????? ????????????????Щ?к????????????
	?????????????????
	???????? /etc/passwd??root????????
	????nl /etc/passwd | sed '/root/p'
	????1  root:x:0:0:root:/root:/bin/bash
	????1  root:x:0:0:root:/root:/bin/bash
	????2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh
	????3  bin:x:2:2:bin:/bin:/bin/sh
	????4  sys:x:3:3:sys:/dev:/bin/sh
	????5  sync:x:4:65534:sync:/bin:/bin/sync
	????....???????
	???????root?????????????????У????????????С?
	???????-n??????????????????С?
	????nl /etc/passwd | sed -n '/root/p'
	????1  root:x:0:0:root:/root:/bin/bash
	?????????????????
	???????/etc/passwd???а???root???У??????????
	????nl /etc/passwd | sed  '/root/d'
	????2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh
	????3  bin:x:2:2:bin:/bin:/bin/sh
	????....???????
	????#????е????root????????
	?????????????????????
	????????????eastern???к?
	????????/etc/passwd?????root??????У???к??濱?????е???????????????????÷??????????bash?滻?blueshell??????????У?
	????nl /etc/passwd | sed -n '/root/{s/bash/blueshell/;p}'
	????1  root:x:0:0:root:/root:/bin/blueshell
	?????????滻/etc/passwd??????bash??????blueshell?????
	????nl /etc/passwd | sed -n '/bash/{s/bash/blueshell/;p;q}'
	????1  root:x:0:0:root:/root:/bin/blueshell
	???????q???????
	???????????????滻
	???????????е????????? sed ?????????????λ???в???????????????????????? sed ?????????????? vi ????????????е?????????
	????sed 's/???????????/?μ????/g'
	??????????????????? /sbin/ifconfig ??? IP
	????[root@ wwww ~]# /sbin/ifconfig eth0
	????eth0 Link encap:Ethernet HWaddr 00:90:CC:A6:34:84
	????inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
	????inet6 addr: fe80::290:ccff:fea6:3484/64 Scope:Link
	????UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
	????.....(???????).....
	??????????ip??192.168.1.100??
	?????? IP ??????????????
	????[root@ wwww ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g'
	????192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
	??????????????????????????????? 192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
	?????? IP ???????????????
	????[root@ wwww ~]# /sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g'
	????192.168.1.100
	????????
	???????sed???????/etc/passwd?????е??β???????????bash?滻?blueshell
	????nl /etc/passwd | sed -e '3??$d' -e 's/bash/blueshell/'
	????1  root:x:0:0:root:/root:/bin/blueshell
	????2  daemon:x:1:1:daemon:/usr/sbin:/bin/sh
	????-e???????????????????????/etc/passwd?????е??β????????????????????bash?滻?blueshell??
	?????????????????(Σ?????)
	????sed ??????????????????????????ù?????????????????? ???????????????????????????????????????????????????????????????? ??????????????? regular_express.txt ???????????????
	???????? sed ?? regular_express.txt ?????н?β??? . ???? !
	????[root@ wwww ~]# sed -i 's/.$/!/g' regular_express.txt
	???????? sed ????? regular_express.txt ????м???# This is a test??
	????[root@ wwww ~]# sed -i '$a # This is a test' regular_express.txt
	??????? $ ??????????У??? a ????????????????????????????# This is a test????
	????sed ??? -i ?????????????????????????????а???????????????????????? 100 ???е???????????? 100 ?м??Щ??????????? vim ?????????????????????????????? sed ??????? sed ??????/??????????????????????? vim ??????
??????
					
					???·???
App??С????H5?????????????????Щ??
2024/9/11 15:34:34?????????????????????????
2024/9/10 11:13:49P-One ???????????????????????????????????????
2024/9/10 10:14:12???????????????????????????
2024/9/9 18:04:26??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44
					
			
								
								
								
								
								
								
								
								
								
								
				
sales@spasvo.com