Using UNIX and Regex Consider the files addr and errorCode below: $ cat addr Xia
ID: 3875865 • Letter: U
Question
Using UNIX and Regex
Consider the files addr and errorCode below:
$ cat addr
Xiao Li, lxiao@unc.edu, 6705462234, Jackson, NC 764
Elizi Moe, emoe@ncsu.edu, 5208534566, Tempe, AZ 85282
Ma Ta, mta@yahoo.com, 4345667345, Austin, TX 91030
Diana Cheng, dcheng@asu.edu, 5203456789, Matitsi, WY 4587
Jackson Five, jfive@ncsu.edu, 5206564573, Kyenta, AZ 85483
Adi Srikanth Reddy, sadi1@imap1.asu.edu, 6578904566, Wyo, WS 67854
Natkin William, wnatkin@imap28.asu.edu, 8044344528, Richmond, VA 22345
$ cat errorCode
Error in the previous line.
Provide the sed command to insert the file errorCode after each line with invalid zip code.
Explanation / Answer
Above sed code will validate the ZIP code let me explain
In this sed code used regular expression it is used to extract the data as per user requirement rather than this code it ignore all the code which is not matching to this.
ad per given data have 2 characters and more than if it is lessthan 2 coded is invalid
[ : alpha : ] it indicates [ A - Z or a - z ]
{1 } it indicates length
as per given data number must be more than 4 and less than 6 then it is valid code
so we are taking the rane as 1 - 3 if the input code is in this range the it is invalid
{ 1- 3 } it indicates range
1 is for charatcters in zip code
2 is for digits in zip code
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.