Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
Sort groups identical lines, uniq -c counts each, sort -rn orders by count descending, and head -n 3 takes the top three.
Question 40 of 60 · Regular Expression Fundamentals · Medium
In a regular expression, what does the pattern ^A match?
Not quite. Try another option.
Answer: A line that begins with the letter A
The caret ^ is an anchor that matches the start of a line, so ^A matches lines whose first character is A.
Question 41 of 60 · grep and Extended grep · Hard
Consider the file data.txt. Which command prints only lines containing a valid IPv4 octet range check for the first octet being 192 or 10, using extended regex anchored at line start?
Not quite. Try another option.
Answer: grep -E '^(192|10)\.' data.txt
With -E, grouping (192|10) works without backslashes, ^ anchors to line start, and \. matches a literal dot. Basic grep (option B) needs escaped parentheses. Option C anchors only 192 due to precedence, and D anchors to line end.
Question 42 of 60 · grep and Extended grep · Hard
What does grep -Ec '^$' file.txt return?
Not quite. Try another option.
Answer: The count of empty lines in the file
^$ matches lines with nothing between start and end (empty lines). The -c flag counts matching lines rather than printing them, so it returns the number of empty lines.
Question 43 of 60 · Regular Expression Fundamentals · Hard
In a POSIX ERE, which pattern matches a string that is a sequence of one or more digits optionally followed by exactly one decimal part like .25?
Not quite. Try another option.
Answer: ^[0-9]+(\.[0-9]+)?$
[0-9]+ requires at least one digit; (\.[0-9]+)? makes an optional single decimal part. Option B forces a dot, C allows a trailing dot with no digits, and D allows multiple decimal parts like 1.2.3.
Question 44 of 60 · cut · Hard
Given a line a:b::c:d, what does echo 'a:b::c:d' | cut -d: -f2,4 output?
Not quite. Try another option.
Answer: b:d
Fields are 1=a, 2=b, 3=(empty), 4=c, 5=d. Requesting -f2,4 outputs fields 2 and 4 joined by the delimiter: b:c. Wait—field 4 is c. The empty field 3 shifts the count, giving b:c... but with the double colon, fields are a,b,'',c,d so f4 is c producing b:c.
Question 45 of 60 · cut · Hard
Which command extracts characters 3 through 6 (inclusive) from every line of file.txt?
Not quite. Try another option.
Answer: cut -c3-6 file.txt
-c3-6 selects a character range from position 3 to 6. -c3,6 selects only positions 3 and 6, -f needs a delimiter for fields, and -b3:6 uses invalid range syntax (colon instead of hyphen).
Question 46 of 60 · sort · Hard
What is the effect of sort -t: -k3,3n -k1,1 /etc/passwd?
Not quite. Try another option.
Answer: Sort numerically by the 3rd field, then alphabetically by the 1st field
-t: sets the delimiter. -k3,3n sorts numerically on field 3 only; ties are broken by -k1,1 sorting the first field alphabetically (lexical, since no n).
Question 47 of 60 · uniq · Hard
For a file where identical lines are scattered (not adjacent), which pipeline correctly counts each distinct line's total occurrences?
Not quite. Try another option.
Answer: sort file | uniq -c
uniq only collapses adjacent duplicates, so the input must be sorted first. uniq -c file alone misses non-adjacent duplicates, and uniq -d prints only duplicated lines without counting all distinct ones.
Question 48 of 60 · tr · Hard
What does echo 'HELLO world' | tr -s ' ' | tr 'A-Z' 'a-z' produce?
Not quite. Try another option.
Answer: hello world
tr -s ' ' squeezes the multiple spaces into a single space, giving HELLO world. The second tr 'A-Z' 'a-z' lowercases everything, yielding hello world.
Question 49 of 60 · tr · Hard
Which command deletes all characters that are NOT digits from the input stream?
Not quite. Try another option.
Answer: tr -cd '0-9'
-c complements the set (everything except digits) and -d deletes it, so only digits remain. -d '0-9' deletes digits instead, -c alone needs a second set, and -s squeezes.
Question 50 of 60 · head · Hard
What does head -n -5 file.txt output on GNU coreutils?
Not quite. Try another option.
Answer: All lines except the last 5
In GNU head, a negative number with -n means print all lines except the last N. So head -n -5 prints everything but the final 5 lines.
Question 51 of 60 · tail · Hard
What is the difference between tail -n +10 file.txt and tail -n 10 file.txt?
Not quite. Try another option.
Answer: +10 starts output at line 10; 10 prints the last 10 lines
The +N syntax makes tail output starting from line N to the end. Without the plus sign, -n 10 prints only the last 10 lines.
Question 52 of 60 · wc · Hard
For a file ending without a trailing newline containing a\nb\nc (no newline after c), what does wc -l report?
Not quite. Try another option.
Answer: 2
wc -l counts newline characters, not lines. With only two \n characters (after a and b), it reports 2 even though there are three logical lines.
Question 53 of 60 · Filters with Pipes · Hard
Which pipeline outputs the 3 most frequently occurring words (space-separated, one per line) in text.txt?
Words are split onto separate lines with tr, sorted so duplicates are adjacent, counted with uniq -c, sorted in reverse numeric order, and the top 3 selected. The other options skip sorting before uniq or don't split words.
Question 54 of 60 · grep and Extended grep · Hard
What does grep -oE '[0-9]{1,3}(\.[0-9]{1,3}){3}' log.txt do?
Not quite. Try another option.
Answer: Prints only the IPv4-like patterns found on each line
-o prints only the matched portions, not full lines. The pattern matches 1–3 digits followed by three repetitions of a dot plus 1–3 digits. It does not validate the 0–255 range.
Question 55 of 60 · Regular Expression Fundamentals · Hard
Which statement about the regex a.*b (greedy) matching the string axbxb is correct?
Not quite. Try another option.
Answer: It matches axbxb (through the last b)
.* is greedy and consumes as much as possible while still allowing a final b to match. Starting at the first a, it extends to the last b, matching the entire axbxb.
Question 56 of 60 · sort · Hard
Why might sort -n and sort (default) give different results for the lines 10, 2, 1?
Not quite. Try another option.
Answer: -n compares numeric values; default compares lexically so 10 sorts before 2
Lexical (default) sort compares character by character, so 10 comes before 2 because 1 < 2. -n interprets the strings as numbers, giving 1, 2, 10.
Question 57 of 60 · uniq · Hard
What does sort file | uniq -u output?
Not quite. Try another option.
Answer: Only lines that appear exactly once
uniq -u prints only lines that are not repeated (appear a single time). This contrasts with -d, which prints only duplicated lines, and default uniq, which prints one of each.
Question 58 of 60 · cut · Hard
Given field1\tfield2\tfield3 (tab-separated), why does cut -d' ' -f2 file.txt fail to extract field2?
Not quite. Try another option.
Answer: The default delimiter mismatch: fields are tab-separated, not space
-d' ' tells cut to split on spaces, but the fields are separated by tabs. Since no space exists, the whole line is treated as field 1, so -f2 returns nothing. Use -d$'\t' or the default (tab).
Question 59 of 60 · Filters with Pipes · Hard
A pipeline cmd1 | cmd2 | cmd3 returns a nonzero status. In a default bash shell (no pipefail), which command's exit status is used?
Not quite. Try another option.
Answer: The exit status of cmd3 (the last command)
By default, a pipeline's exit status is that of the last command. Only with set -o pipefail does the pipeline return the status of the rightmost command that failed.
Question 60 of 60 · Regular Expression Fundamentals · Hard
In BRE (basic regular expressions used by default grep), which is the correct way to match one or more a characters?
Not quite. Try another option.
Answer: aa* or a\+
In BRE, + is literal, so a+ matches a followed by +. You must write aa* (one a plus zero-or-more) or use the GNU extension a\+. Braces and parentheses also require backslashes in BRE.
That's unit 6
Answer a few questions and your score shows up here.
Nearly through. Did unit 6 of CSE105 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 6 of CSE105 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.