QuizzesText Processing — grep, awk, sed, cut, sort — Concept Check
intermediate
linux

Text Processing — grep, awk, sed, cut, sort — Concept Check

Questions on Text Processing — grep, awk, sed, cut, sort. Linux text processing tools — grep, awk, sed, cut, sort, uniq — are the foundation of log analysis, data extraction, and pipeline automation. Combining them with pipes creates powerful one-liners.

8 minutes 8 questions Pass at 70%
Time Limit
8 minutes - timer starts when you begin
Change Answers Freely
Revisit and change any answer before submitting
Full Review After Submit
Correct answers and explanations shown for every question
Auto-submit on timeout
Quiz submits automatically when time runs out

Questions in this quiz

8 questions on Text Processing — grep, awk, sed, cut, sort — Concept Check. Work through them here, then start the quiz to answer them and see your score.

  1. 1.A log file contains multiple entries with varying error levels. You want to filter out only the lines containing 'ERROR' or 'FATAL'. Which command should you use?

    • Agrep -E 'ERROR|FATAL' logfile
    • Bgrep -v 'DEBUG' logfile
    • Cgrep 'ERROR|FATAL' logfile
    • Dgrep -i 'error' logfile
  2. 2.You need to replace all occurrences of 'password' with 'REDACTED' in a log file. Which command accomplishes this?

    • Aawk '{gsub(/password/, "REDACTED")}' logfile
    • Bgrep 'password' logfile | sed 's/password/REDACTED/'
    • Csed 's/password/REDACTED/g' logfile
    • Dcut -d' ' -f1 logfile | sed 's/password/REDACTED/g'
  3. 3.A developer wants to count the number of unique IP addresses in a web server log. Which command sequence should they use?

    • Ased -n '/IP/p' access.log | uniq -c
    • Bawk '{print $1}' access.log | sort | uniq | wc -l
    • Cgrep -c 'IP' access.log
    • Dcut -d' ' -f1 access.log | sort | wc -l
  4. 4.You want to extract the usernames and UIDs from /etc/passwd where UIDs are greater than or equal to 1000. Which command should you use?

    • Ased -n '/UID>=1000/p' /etc/passwd
    • Bawk -F: '$3 >= 1000 {print $1, $3}' /etc/passwd
    • Ccut -d: -f1,3 /etc/passwd | grep 'UID>=1000'
    • Dgrep -E 'UID>=1000' /etc/passwd
  5. 5.A user wants to sort a list of files by their size in human-readable format. Which command should they use?

    • Asort -n filelist.txt
    • Bsort -k5 -rh filelist.txt
    • Ccut -d' ' -f5 filelist.txt | sort
    • Dawk '{print $5}' filelist.txt | sort -h
  6. 6.How can you print lines 10 to 20 from a file using sed?

    • Ased '10,20d' file
    • Bawk 'NR>=10 && NR<=20' file
    • Csed -n '10,20p' file
    • Dcut -d' ' -f10-20 file
  7. 7.You want to count the number of lines containing the word 'error' in a log file, ignoring case. Which command is correct?

    • Agrep -c 'error' logfile
    • Bgrep -i -c 'error' logfile
    • Csed -n '/error/p' logfile | wc -l
    • Dawk '/error/ {count++} END {print count}' logfile
  8. 8.Which command sequence finds the top 10 most-requested URLs in an nginx access log?

    • Agrep 'GET' access.log | awk '{print $7}' | sort | head -10
    • Bawk '{print $7}' access.log | sort | uniq -c | sort -rn | head -10
    • Csed -n '/GET/p' access.log | awk '{print $7}' | sort | uniq -c
    • Dcut -d' ' -f7 access.log | sort | uniq -c | head -10