I was wondering if I could get help solving this problem. Write a regular expres
ID: 3885440 • Letter: I
Question
I was wondering if I could get help solving this problem.
Write a regular expression (not a grep command) that matches the following format, where "Month" is the full name of a month: Month, DD YYYY Write a command that counts the number of blank lines in custdata.txt Write a command that outputs the number of lines in custdata.txt that have two words in a row that start with capital letters (with only spaces between). Write a command that lists all data values (no parameter value) from data.txt that have the same digit three times in a row, with the results being a sorted listExplanation / Answer
NOTE: there is no language or environment mentioned. So i am using it is unix and regular expressions because one of the question has quoted about grep command. Please check the answers for questions and let me know if you have any questions. I will revert back within 24 hours.
1)
Date format: Month, DD YYYY
Ans) w+, d{2} d{4}
the above regular expression will match the date format "Month, DD YYYY" where Month is a full month name
2)
grep -c '^$' <filename>
The above comand can count the number of blank lines in a given filename. For example,
Unix Terminal> cat custdata.txt
krishna
hello
world
how
are
you
Unix Terminal> grep -c '^$' custdata.txt
4
It counts the number of blank lines in the file custdata.txt
3)
The regex can be used for this questions is "[A-Z]w+ [A-Z]w+" where we are trying to match the first character as uppercase for two consecutive words followed by any alphanumberic(w+) character. Below is the command in execution.
Unix Terminal> cat custdata.txt
krishna hello How Are
hello hi How Do you do
world is so Small
how can i help you
are you running this File
you
Hello how are You Darling why Do You think This is Valid. Not sure Why You are such
Unix Terminal> cat custdata.txt|grep -E '[A-Z]w+ [A-Z]w+'
krishna hello How Are
hello hi How Do you do
Hello how are You Darling why Do You think This is Valid. Not sure Why You are such
Unix Terminal>
4)
We could use a regular expression like (d).*.* where it will match any digit in a row first followed by the same digit occurred three times. Note that .* represents any characters in between and represents the digit captured in (d). is used to ensure the same digit occurred thrice. Below is the command output.
Sorry i did not understand what sorted list mean by in the question. Thats why i have written the regular expression required. Please share sample input and output expected so i can complete the same question with results as sorted list.
Unix Terminal> cat data.txt
1 2 3 4 1 2 1
1 2 3 4 5 5
2 3 4 5 3 3 3
1 9 1 9 9 1
1 2 2 2 1
1 1 2 3 2
2 2 3 4 3
1 1 2 2 3 3
Unix Terminal> cat data.txt|grep -E '(d).*.*'
1 2 3 4 1 2 1
2 3 4 5 3 3 3
1 9 1 9 9 1
1 2 2 2 1
Unix Terminal>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.