"SED" personal use of the method to record

Source: Internet
Author: User

SED is broad and profound, I am in addition to simple usage, others in the work has not been deeply researched.

Another, attach several blog articles, follow up may update this list:

    1. SED command detailed: http://www.cnblogs.com/edwardlost/archive/2010/09/17/1829145.html

    2. Sed single-line script Quick reference: http://blog.csdn.net/showman/article/details/4408937

"SED" Delete Comment # and blank line:sed  '/ *#/d; /^ *$/d ' Count rows:sed -n  ' $= '  log/query.log  2546 Delete space:sed  ' s/\ //g ' delete]:sed  ' s/]//g ' match line before (I, after A) add A line:sed -i  '/-a input -j  reject --reject-with icmp-host-prohibited/i\-a input -p tcp -m state  --state new -m tcp --dport 10050 -j accept '  rc.firewall.txtsed  -i  '/-A INPUT -P ICMP -J ACCEPT /A\-A INPUT -P VRRP  -j accept '  rc.firewall.txt Remove the specified character sed  ' s/insert ignore//g '  1.txt |sed  ' S/insert//g '  |sed  ' s/\ //g '  |sort |uniq -c |sort -nr |more intercept content, According to the time period:sed -n  '/2013:14:00:00/,/2013:14:40:00/p '  0305.log > 1400.1440.logzcat  2014-06-17-0000-2330_msg.ecqun.com.cn.log.gz |sed -n  '/2014:08:00:00/,/2014:10:00:00/p '  | More replace:echo  "/HTTP/192.168.0.154:10010/?from=pek&to=sha&date=2013-12-02&enddate=2013-12-02&type=text " |  sed -r  "s/([0-9]{4}-[0-9]{2}-[0-9]{2})/$ (date +%f)/g" echo  "20140625232336"  |sed   -r  ' s/([0-9]{4}) ([0-9]{2}) ([0-9]{2}) ([0-9]{2}) ([0-9]{2}) ([0-9]{2})/\1-\2-\3 \4:\5:\6/'                       2014-06-25 23:23:36 print the specified line:sed -n  ' 2p '  1630.1650.log_7_1 delete the specified line:sed  1,8d wan. ip  two lines and one line:sed  ' n;s/\n//' Note that the following usage and the above difference:sed  ': A; N;s/\n//;ta ' sed  ': A;...; Ta ' 's role:: A means: Create a label A;ta means: If the execution succeeds, jump to label A to continue execution t labelif  a s/// has done a  successful substitution since the last input line was read  And since the last t or t command, then branch to label ;  if label is&nbsP;omitted, branch to end of script. To add, the previous s///substitution statement succeeds before jumping to the label-------------------" P " command prints the buffer  (Remember to use -n option with   "P")   "D"  command is just opposite, its for deletion.  ' d '  will delete the pattern space buffer and immediately starts  the next cycle. p:print up to the first embedded newline  of the current pattern space. d:if pattern space contains no newline, start a normal new  Cycle as if the d command was issued. otherwise, delete text  in the pattern space up to the first newline, and  Restart cycle with the resultant pattern space,&nbsP;without reading a new line of input. N:add a newline to the pattern space, then append the next  line of input to the pattern space. if there is no  more input then sed exits without processing any more  Commands.


"SED" personal use of the method to record

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.