Bird
0
0

What will be the output of this bash command?

medium📝 Command Output Q13 of 15
Bash Scripting - Text Processing in Scripts
What will be the output of this bash command?
echo "apple banana cherry" | awk '{print $2}'
Aapple
Bcherry
Capple banana
Dbanana
Step-by-Step Solution
Solution:
  1. Step 1: Understand the input and awk command

    The input string is "apple banana cherry". Awk splits input by spaces and $2 refers to the second word.
  2. Step 2: Identify the second word

    The second word is "banana".
  3. Final Answer:

    banana -> Option D
  4. Quick Check:

    awk $2 = second word = banana [OK]
Quick Trick: awk $2 prints the second word from input [OK]
Common Mistakes:
MISTAKES
  • Confusing $1 and $2 fields
  • Expecting full line output
  • Not splitting input by spaces

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes