sed

-n 打印匹配的行(p:打印):sed -n 'p' /etc/passwd

pattern:

匹配第4行:sed -n '4p' /etc/passwd

匹配3-11行:sed -n '3,11 p' /etc/passwd

匹配00的行:sed -n '/00/ p' /etc/passwd

匹配开头到结尾的行:sed -n '/^xiang01/,/xiang03/p' /etc/passwd

xiang01:x:1006:1009::/home/xiang01:/bin/sh
xiang02:x:1007:1010::/home/xiang02:/bin/sh
xiang03:x:1008:1011::/home/xiang03:/bin/sh

匹配51到最后一行:sed -n '51,$ p' /etc/passwd

 

/bin/sh的行:sed -n '/\/bin\/sh/ p' /etc/passwd
yang2:x:1001:1001::/home/yang2:/bin/sh
yang04:x:1002:1005::/home/yang04:/bin/sh
u1:x:1003:1006::/home/u1:/bin/sh
u2:x:1004:1007::/home/u2:/bin/sh
u3:x:1005:1008::/home/u3:/bin/sh
xiang01:x:1006:1009::/home/xiang01:/bin/sh
xiang02:x:1007:1010::/home/xiang02:/bin/sh
xiang03:x:1008:1011::/home/xiang03:/bin/sh

 

上一篇:Shell:awk工具


下一篇:Ubuntu安装PostgreSQL、并使用OmniDB查看