Bird
0
0

You want to extract the 2nd and 4th fields from a colon-separated file and then paste them side by side separated by a semicolon. Which command sequence achieves this?

hard🚀 Application Q9 of 15
Bash Scripting - Text Processing in Scripts
You want to extract the 2nd and 4th fields from a colon-separated file and then paste them side by side separated by a semicolon. Which command sequence achieves this?
Acut -d ';' -f 2,4 file.txt | paste -d ':'
Bcut -d ':' -f 2 file.txt | cut -d ':' -f 4 file.txt | paste -d ';'
Ccut -d ':' -f 2 file.txt | paste -d ';' - <(cut -d ':' -f 4 file.txt)
Dpaste -d ':' -f 2,4 file.txt | cut -d ';'
Step-by-Step Solution
Solution:
  1. Step 1: Extract fields 2 and 4 separately

    cut -d ':' -f 2 file.txt pipes field 2 values to paste stdin; <(cut -d ':' -f 4 file.txt)> provides field 4 via process substitution.
  2. Step 2: Paste with custom delimiter

    paste -d ';' - <(cut ...)> joins corresponding lines from both inputs with semicolon.
  3. Final Answer:

    cut -d ':' -f 2 file.txt | paste -d ';' - <(cut -d ':' -f 4 file.txt)> -> Option C
  4. Quick Check:

    cut separate fields + paste process substitution = f2;f4 per line [OK]
Quick Trick: Use process substitution <(cut...) for paste second input [OK]
Common Mistakes:
MISTAKES
  • Trying to cut twice separately
  • Mixing delimiters incorrectly
  • Misusing paste options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes