Command 11 –
———-
Find text at the start of line [ ^ ]
awk -F "|" '$2-/^s/{print $0}' tabfile.txt
Command 12 –
———-
Find text at the ent of line [ $ ]
awk -F "|" '$2 -/n$/{print $0}' file1.txt
Command 13 –
———-
perform condition check using if
awk -F "|" '{if ($3>2000) print $0;}' file2.txt
Command 14 –
———-
perform condition check using if-else
awk -F "|" '{if($3>=20000) print $2;
else print "*****" ; }' file2.txt
command 15 –
——–
perform condition check using else if
awk -F "|" '{
if ($3>=3000) print $2 "your tax is 30%";
else if($3>=2000) print $2 "your tax is 20%";
else print $2 "your tax is 10%;}' file2.txt
Command 16 –
——–
Begin Block
{Begin Block} {Action} {End}
awk -F "|" 'BEGIN{print "Display records"}{if($3==1000) print$0}' file2.txt
awk -F "|" 'BEGIN{salary=2}{if($3==1000){$3=$3*2;print$0;}' file2.txt
Command 17 –
———
End Block
awk -F "|" {if($3>1000) print $0}END{print "Task is done"}' file2.txt
Command 18 –
———
While Loop
awk -F"|" {i=1;while(i<=2){print $0; i++}} file2.txt
awk -F"|" '{i=1;while(i<=3){print $i; i++;}}' file2.txt
Command 19-
———
For Loop
awk -F "|" '{for(i=1;i<=2;i++){print $0}}' file2.txt