Bird
0
0

How can you combine text processing tools to count unique IP addresses from a web server log file?

hard🚀 Application Q9 of 15
Bash Scripting - Text Processing in Scripts
How can you combine text processing tools to count unique IP addresses from a web server log file?
AUse awk to extract IPs, sort them, then use uniq -c to count occurrences
BUse grep to find IPs and echo to count them
CUse sed to delete all lines except IPs and wc -l to count
DUse cat and head to display first IP and count
Step-by-Step Solution
Solution:
  1. Step 1: Extract IP addresses with awk

    Awk can select the IP field from each log line.
  2. Step 2: Sort and count unique IPs

    Sorting prepares data for uniq -c, which counts repeated lines.
  3. Final Answer:

    Use awk to extract IPs, sort them, then use uniq -c to count occurrences -> Option A
  4. Quick Check:

    Awk + sort + uniq = C [OK]
Quick Trick: Chain awk, sort, and uniq to count unique text items [OK]
Common Mistakes:
MISTAKES
  • Using grep and echo incorrectly for counting
  • Deleting lines with sed instead of extracting
  • Counting only first IP with head

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes