Friday, April 1, 2016
Bash GREP Showing Exact Email Addresses Matches from Text File
April 01, 2016
beginner
,
code
,
easy
,
email matching
,
email regex
,
exact match
,
explanation
,
grep
,
linux
,
match from file
,
piping
,
regex
,
regex grep color
,
regular expression
,
script
,
shell
,
tutorial
What the code does:
The code below uses GREP to match specific pattern within the text file. If the exact match is found then it show that match in console.Bash Script Code:
Save the code below in a file with extension ".sh". For example,GrepRegexExactEmailMatch.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
grep --color -E -w "^[A-Za-z0-9._]+@[A-Za-z0-9.]+\.[A-Za-z]{2,6}" "EmailAddress.txt" |
Input File:
Save the text below in a file named "EmailAddress.txt"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Valid Email addresses: | |
google@gmail.com | |
afsjk_wegkj@yahoo.com | |
asdsd/1221@asd.asd.sd.rtg.erer.erer | |
abcd@cse.uiu.ac.bd | |
Invalid email addresses: | |
asdgh@asd@gmail.com reason: number of @ is more than one | |
hello@asdsd reason: no .domain name | |
hasan@.com reason: At least one charecter needed between @ and . |
Running the Code:
Before doing anything make sure the text file and the script file are located in the same directory. In order to run the code just type the code below if you named your script file as "GrepRegexExactEmailMatch.sh".bash GrepRegexExactEmailMatch.sh
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment