Linux Shell Programming---Parsing email addresses and URLs in text

Source: Internet
Author: User

resolves the e-mail address in the text and URL

(1) , usage scenarios

parsing the required text from a given file is a common task in text processing. such as e-mail addresses,URLs , etc. can be found with appropriate regular expressions. We often need to parse and extract e-mail addresses from an e-mail customer list or HTML page that contains a large number of unrelated characters and words .


(2) , regular match

The regular expression that matches an e-mail address is as follows:

[A-za-z0-9._] [Email protected] [A-za-z0-9.] +\. [A-za-z] {2,4}

Match HTTP URL the regular expression is as follows:

Http://[a-za-z0-9\-\.] +\. [A-za-z] {2,4}


(3) , Example

Example 1 : Match Email

[Email protected]_01t]# cat A5.txt

This is aline of text contains,<email> #[email protected] </email> Andemail address,

Blog "http://www.google.com", [email protected] DFDFDFDDDFDF; [Email protected]<br/>

<ahref= "Http://code.google.com" >

[Email protected]_01t]# cat a5.txt |grep-e-O "[A-za-z0-9._][email protected][a-za-z0-9.] +\. [A-za-z] {2,4} "

[Email protected]

[Email protected]

[Email protected]

[[Email protected]_01t]#

Example 2 : Match URL

[Email protected]_01t]# cat A5.txt

This is aline of text contains,<email> #[email protected] </email> Andemail address,

Blog "http://www.google.com", [email protected]; [Email protected]<br/>

<ahref= "Http://code.google.com" >

[Email protected]_01t]# cat a5.txt |grep-e-O "http://[a-za-z0-9\-\.] +\. [A-za-z] {2,4} "

http://www.google.com

Http://code.google.com

[[Email protected]_01t]#


This article is from the "operation and maintenance of micro-letter" blog, please be sure to keep this source http://weixiaoxin.blog.51cto.com/13270051/1963698

Linux Shell Programming---Parsing email addresses and URLs in text

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.