Bird
0
0

You have a log file with lines like:

hard📝 Application Q8 of 15
Linux CLI - Text Processing
You have a log file with lines like:
2024-06-01 ERROR Disk full
2024-06-01 INFO Backup started
2024-06-02 ERROR Network down

Which command extracts only the dates of ERROR lines?
Agrep 'ERROR' logfile | cut -d' ' -f3
Bgrep 'ERROR' logfile | awk '{print $1}'
Csed -n '/ERROR/p' logfile | cut -d' ' -f2
Dawk '/ERROR/ {print $2}' logfile
Step-by-Step Solution
Solution:
  1. Step 1: Identify ERROR lines

    grep 'ERROR' filters lines containing 'ERROR'.
  2. Step 2: Extract date field

    Date is the first field ($1), so awk '{print $1}' prints the date.
  3. Final Answer:

    grep 'ERROR' logfile | awk '{print $1}' -> Option B
  4. Quick Check:

    Filter ERROR then print first field = D [OK]
Quick Trick: Filter then print needed field for precise extraction [OK]
Common Mistakes:
  • Printing wrong field number
  • Using cut with wrong delimiter or field
  • Confusing INFO and ERROR lines

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes