[Linux] using awk to intercept text snippet examples

Source: Internet
Author: User

String processing under Linux, simple can use grep/egrep, cut, processing complex can use SED, awk.

Awk can handle not only the line string, but also the paragraph, and here's an example of using awk to intercept the section interval usage.

Cases:

Cat try.txt aaaa123123bbbb456456ccc123456ddd123k123abc### #截取从bbbb这行到首个123行之间的段落awk '/bbbb/,/123/' try.txt results for: BBBB4 56456ccc123456ddd


Using Python3

#!/usr/bin/env pythonimport Rewith Open (' Try.txt ', ' R ') as F:content = F.read () result=re.findall ('. *123123 (. *?) Ccc.* ', Content,re. S) # # # # # # # # (. *?) Represents all characters except newline, re. s make. Matches all characters including line break for a in Result:print (a) result is: bbbb456456


[Linux] using awk to intercept text snippet examples

Related Article

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.