Bird
0
0

You have a file records.txt with tab-separated values. You want to extract the 1st and 3rd columns but only if the 3rd column is not empty. Which command correctly does this?

hard📝 Application Q15 of 15
Linux CLI - Text Processing
You have a file records.txt with tab-separated values. You want to extract the 1st and 3rd columns but only if the 3rd column is not empty. Which command correctly does this?
Acut -f 1,3 records.txt | grep -v '^\t$' | cut -f 3
Bawk -F '\t' '$3 != "" {print $1, $3}' records.txt
Ccut -f 1,3 records.txt | grep -v '^\t$'
Dcut -f 1,3 records.txt | grep '^\t$'
Step-by-Step Solution
Solution:
  1. Step 1: Understand cut limitation

    cut extracts columns but cannot filter lines based on content.
  2. Step 2: Use a tool that filters lines by field content

    awk can check if the 3rd field is not empty and print the 1st and 3rd fields.
  3. Step 3: Analyze options

    awk -F '\t' '$3 != "" {print $1, $3}' records.txt uses awk with tab delimiter and condition $3 != "", printing fields 1 and 3 correctly.
  4. Final Answer:

    awk -F '\t' '$3 != "" {print $1, $3}' records.txt -> Option B
  5. Quick Check:

    Use awk to filter and extract columns [OK]
Quick Trick: Use awk for filtering and extracting columns together [OK]
Common Mistakes:
  • Trying to filter lines using cut alone
  • Using grep incorrectly to filter empty fields
  • Not specifying correct delimiter in awk

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes