sed截取某个区间的内容


l00291777@linux-host-10_67_189_50:~/practice> cat data_passwd.txt
at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash
bin:x:1:1:bin:/bin:/bin/bash
daemon:x:2:2:Daemon:/sbin:/bin/bash
dhcpd:x:105:65534:DHCP server daemon:/var/lib/dhcp:/bin/false
ftp:x:40:49:FTP account:/srv/ftp:/bin/bash
games:x:12:100:Games account:/var/games:/bin/bash

1、如果知道行号,可以根据行号来截取

l00291777@linux-host-10_67_189_50:~/practice> sed -n '1,4p' data_passwd.txt
at:x:25:25:Batch jobs daemon:/var/spool/atjobs:/bin/bash
bin:x:1:1:bin:/bin:/bin/bash
daemon:x:2:2:Daemon:/sbin:/bin/bash
dhcpd:x:105:65534:DHCP server daemon:/var/lib/dhcp:/bin/false


2、如果不知道行号,可以根据正则表达式来截取

l00291777@linux-host-10_67_189_50:~/practice> sed -n '/bin:x:1/,/dhcpd:x:105/p' data_passwd.txt
bin:x:1:1:bin:/bin:/bin/bash
daemon:x:2:2:Daemon:/sbin:/bin/bash
dhcpd:x:105:65534:DHCP server daemon:/var/lib/dhcp:/bin/false

你可能感兴趣的:(sed截取某个区间的内容)