2018-03-13 Linux Learning

Source: Internet
Author: User
Tags bacula

9.4 sed (UP)

Sed tool example sed-n ' 5 ' p test.txt sed-n ' 1,5 ' p test.txt sed-n ' 1,$ ' P test.txt sed-n '/root/' P test.txt sed -N '/^1/' P test.txt sed-n ' in$ ' P test.txt sed-n '/R. o/' P test.txt sed-n ' oo* ' P test.txt sed-e ' 1 ' p-e '/111/' p-n test.txt [[email protected] sed]# sed-n '/R oot/' P test.txt root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin [[Email protec    Ted] sed]# sed-nr '/o+t/' P test.txt root:x:0:0:root:/root:/bin/bash operator:x:11:0:operator:/root:/sbin/nologin [[email protected] sed]# sed-n ' 2,5 ' p test.txt bin:x:1:1:bin:/bin:/sbin/nologin daemon:x:2:2:daemon:/sbin:/ Sbin/nologin adm:x:3:4:adm:/var/adm:/sbin/nologin Lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin [[email protected ] sed]# sed-n ' 1,$ ' P test.txt [[email protected] sed]# sed-n '/^s/' P test.txt Sync:x:5:0:sync:/sbin:/bin/syn C Shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown Systemd-network:x:192:192:systemD Network Management:/:/sbin/nologin sshd:x:74:74:privilege-separated ssh:/var/empty/sshd:/sbin/nologin [[Email&nbs P;protected] sed]# sed-e ' 1 ' p-e '/bus/' p-n test.txt root:x:0:0:root:/root:/bin/bash dbus:x:81:81:system Message Bus:/:/sbin/nologin [[email protected] sed]# sed-e ' 1 ' p-e '/bus/' p-e '/lp/' p-n test.txt root:x:0:0:root:/r Oot:/bin/bash lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin Dbus:x:81:81:system Message Bus:/:/sbin/nologin

9.5 sed (bottom)

-N Use Quiet (silent) mode. In the usage of general sed, all data from STDIN is generally listed on the screen. However, if you add the-n parameter, only the line (or action) that is specially processed by SED is listed. -P Print-I case-insensitive-D Delete-I modify file contents-R plus-R special symbol does not need add \ de-justification s/a/b/g all replace s/a/b/replace first match & represent front parenthesis sed example SE d ' 1 ' d test.txt sed ' 1,10 ' d test.txt sed '/oot/' d test.txt sed ' 1,2s/ot/to/g ' test.txt sed ' s#ot#ss#g ' test.tx t sed ' s/[0-9]//g ' test.txt sed ' s/[a-za-z]//g ' test.txt sed-r ' s/(Rot) (. *) (bash)/\3\2\1/' test.txt sed ' s/^.         *$/123&/' test.txt sed-i ' s/ot/ss/g ' test.txt [[email protected] sed]# sed-n '/user/' Ip test.txt Ftp:x:14:50:ftp user:/var/ftp:/sbin/nologin Polkitd:x:999:997:user for Polkitd:/:/sbin/nologin [[EMAIL&N        bsp;protected] sed]# sed ' 1,18 ' d test.txt bacula:x:133:133:bacula Backup system:/var/spool/bacula:/sbin/nologin Apache:x:48:48:apache:/usr/share/httpd:/sbin/nologin [[email protected] sed]# head-3 test.txt|sed-r ' s/ roo/aaa/' Aaat:x:0:0:root:/root:/bin/bash bin:x:1:1:bin:/bin:/sbin/nologin Daemon:x:2:2:daemon:/sbin:/sbin/nologin [[email protected ] sed]# head-3 test.txt|sed-r ' s/roo/aaa/g ' Aaat:x:0:0:aaat:/aaat:/bin/bash bin:x:1:1:bin:/bin:/sbin/nolog In Daemon:x:2:2:daemon:/sbin:/sbin/nologin [[email protected] sed]# sed ' s#ot#ss#g ' test.txt ro Ss:x:0:0:ross:/ross:/bin/bash [[email protected] sed]# sed ' s/[0-9]//g ' test.txt root:x:::root:/root:/ Bin/bash Bin:x:::bin:/bin:/sbin/nologin [[email protected] sed]# sed ' s/[a-za-z]//g ' test.txt: : 0:0::/://:: 1:1::/://:: 2:2::/://[[email protected] sed]# head-3 test.txt|sed-r ' s/([^:]+):( . *):([^:]+]/\3!\2!\1/'/bin/bash!x:0:0:root:/root!root/sbin/nologin!x:1:1:bin:/bin!bin/sbin/nologin !x:2:2:daemon:/sbin!daemon [[email protected] sed]# head-3 test.txt|sed-r ' s/(. *)/aaa:&/' Aaa:roo t:x:0:0:root:/root:/bin/Bash Aaa:bin:x:1:1:bin:/bin:/sbin/nologin Aaa:daemon:x:2:2:daemon:/sbin:/sbin/nologin 

2018-03-13 Linux Learning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.