Each question is accompanied by a hex number that is the first digit(s) of the shasum of the correct output.

computer science

Description

*****

* Assume questions are case-sensitive unless told otherwise (or to convert case).

* Each question is accompanied by a hex number that is the first digit(s) of the shasum of the correct output.

* Include the specified command, and the shasum of the output.

* Suppose we have multiple text files with contents inside

eg:

0) Display all lines that start with the substring "the". [0]

            cat * | grep "^the" | shasum

            092dda5fe38fe9367e8da9bab3ac231f7b8b6ab6  -

[20; 2 each] ***** PART 1) GREP

*** In the GREP section, you may only use CAT and GREP, unless stated otherwise.

1-3) Using BREs, give 3 different ways to display all lines that start with the substring "the", but not the word "the". [7]         

4) Using BRE(s), display all lines that start with a "t", but not with the substring "the" [d]      

5) Using BREs, display all lines that contain the word "the", but do not contain the word "the" at the beginning or end of the line. [2]

            eg: REJECT "the the x", "x the the"

            eg: ACCEPT "x the x", "them the there"         

6) Using BREs, display all lines that contain an occurrence of the word "the" that is not at the beginning or end of a line. [0]

            eg: REJECT "the x", "x the"

            eg: ACCEPT "x the x", "the the x" "x the the", "the the the"   

7) Display all lines that contain the substring "the" that is not the word "the". [5]

            eg: ACCEPT "mother", "then the", "the thermos"

            EG: REJECT "the", "the a and the b"  

8) Only display the lines before and after a line that contains the substring "the", but do not display any lines that contain the substring "the". Do not display line grouping seperators. [e9]       

9) Using only grep and cut (no cat), display every 5th line of the entire corpus (not of the books individually), starting with line 1. eg: line 1,6,11,16,... No cat, awk, or sed. [27]

10) Display the word that most frequently precedes (comes before) the word "the". Use only cat, grep, sort, uniq.  No awk, sed, cut, head, or tail. [c8]

[20; 2 each] ***** Part 2) SED

*** In the SED section, you may only use CAT and SED unless stated otherwise.

11) Display every 5th line of all text file (not of a file individually), starting with line 1. [27]

12) Replace every word with a number of asterisks equal to its length. [4]

            eg: "and that she has counted me, among the dead."

            ->  "*** **** *** *** ******* **, ***** *** ****."

13) Replace every occurrence of the word "good" with "better" and "better" with "best". [c]

eg: "good, better, best. never let it rest. 'til your good is better and your better is best."

            -> "better, best, best. never let it rest. 'til your better is best and your best is best."

14) On every line that does not contain the substring "safe", replace all occurrences of the substring "out" with "OUT". [4]      

15) Place the line "BEFORE" before every line containing the word "before", and the line "AFTER" after every line containing the word "after" [no quotes]. Do not use 's/' [6]

16) Remove all characters within parenthesis (on the same line). Take the outermost parenthesis. [9]

            eg: "a (b (c) d) e" -> "a () e"

            eg: "a (b) (c) (d) e" -> "a () e"

            eg: "a ((((((b) c" -> "a () c"

            eg: "a (b" -> "a (b"

17) For all lines where the same word occurs twice in a row (with an non-zero number of non-word characters between them), replace the second occurrence with the word 'jinx'. [02]

18) Swap the first and last word on every line. [c0]

            eg: ' "Hi how are you?" ' -> ' "you how are Hi?" '

19) Double every word that contains "two" as a substring, but do not double the word "two" itself. Put one space between them. [a5]

            eg: 'two networks of driftwood for two trustworthy twopence'

            -> 'two networks networks of driftwood driftwood for two trustworthy trustworthy twopence twopence'

20) Remove the line that follows any line that contains the word "missing". [8b]

            eg: 'a\nmissing\nb\nc\n' -> 'a\nmissing\nc\n'


Related Questions in computer science category