Linux CLI - Text ProcessingYou want to print the second field only for lines where the first field starts with 'a' or 'b'. Which awk command achieves this?Aawk '$1 ~ /^[ab]/ {print $2}' file.txtBawk '$1 == "a" || $1 == "b" {print $2}' file.txtCawk '$1 = "a" || $1 = "b" {print $2}' file.txtDawk '$1 ~ /a|b/ {print $2}' file.txtCheck Answer
Step-by-Step SolutionSolution:Step 1: Understand pattern for fields starting with 'a' or 'b'The regex /^[ab]/ matches strings starting with 'a' or 'b'. The operator ~ means regex match.Step 2: Check each option's correctnessawk '$1 ~ /^[ab]/ {print $2}' file.txt uses correct regex and syntax. awk '$1 == "a" || $1 == "b" {print $2}' file.txt compares whole field to 'a' or 'b' exactly, not starts with. awk '$1 = "a" || $1 = "b" {print $2}' file.txt uses assignment '=' instead of comparison '=='. awk '$1 ~ /a|b/ {print $2}' file.txt matches anywhere 'a' or 'b' appears, not just start.Final Answer:awk '$1 ~ /^[ab]/ {print $2}' file.txt -> Option AQuick Check:Regex match start with a or b = awk '$1 ~ /^[ab]/ {print $2}' file.txt [OK]Quick Trick: Use regex ^[ab] to match start of field [OK]Common Mistakes:Using = instead of == for comparisonMatching exact string instead of startUsing wrong regex without ^ anchor
Master "Text Processing" in Linux CLI9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More Linux CLI Quizzes Disk and Storage - du (disk usage by directory) - Quiz 6medium Networking Commands - ping for connectivity testing - Quiz 13medium Pipes and Redirection - /dev/null for discarding output - Quiz 10hard Pipes and Redirection - stdin redirection (<) - Quiz 1easy Pipes and Redirection - Why pipes chain commands into workflows - Quiz 10hard Process Management - jobs command - Quiz 13medium Process Management - Background processes (&) - Quiz 9hard Searching and Finding - which and whereis for commands - Quiz 1easy Text Processing - sort and uniq - Quiz 6medium Text Processing - awk basics (field processing) - Quiz 1easy