Create the following file and label it credit_cards.txt
Joe Smith joeytech password1 3456-3467-0987-2134
Anne Jones annieterror toesandstuff 4567-3478-2334-8078
Kim Stary kimother password2 9087-2347-4759-9097
Tom Nolter nolter087 mypassword 4364-536123-12345
Larry Notting notting198 password3 123-654-321-9-5
Note that the first three credit cards are the pattern for Visa and MasterCard
grep '[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}'
The fourth is the pattern for American Express
The fifth is for JCPenney
Create the proper grep statement that when run will only yield that type of credit card.
create the correct grep statements,
show that they get the correct output and
Created a text file credit_cards.txt with the data which you have provided
To get the pattern for Visa and Mastercard as shown in the example-
grep '[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}-[0-9]\{4\}' credit_cards.txt
Screenshot for the output-
[0-9] means any digit and \{4\} means to match any preceeding four digits
To get the pattern for the American Express
grep '[0-9]\{4\}-[0-9]\{6\}-[0-9]\{5\}' credit_cards.txt
Screenshot for the output-
[0-9] means any digit and \{4\} means to match any preceeding four digits Similary \{6\} and \{5\} means to match any preceeding six digits and four digits respectively.
To get the pattern for JCPenney
grep '[0-9]\{3\}-[0-9]\{3\}-[0-9]\{3\}-[0-9]\{1\}-[0-9]\{1\}' credit_cards.txt
Screenshot for the output-
[0-9] means any digit and \{3\} means to match any preceeding three digits Similary \{3\} and \{1\} means to match any preceeding three digits and one digit respectively.
Get Answers For Free
Most questions answered within 1 hours.