Awk If
ls -l | awk '{ if($5==0) print $9}'
-rw-rw---- 1 nkumarachchi2019 nkumarachchi2019 0 Dec 15 16:47 jobs.cancel
## eg 1 ####################
awk '{
if($3 <= 40)
{
print "The salary of ",$1, " is ", $4, "\n"
}
else
{
print "The age of ",$1, " is ", $3, "\n"
}
}' employee.txt
###########################
## eg 2 #################
{
name=$1;
if ( name=="JACKSON" ) color="Blue";
else if (name=="MARTIN") color="Black";
else if (name=="LILY") color="Red";
else if (name=="ROBINSON") color="White";
else color="None";
if(color!="None") print "The favorite color of ", name, "is ", color;
else print "No person found";
}
#########################
https://linuxhint.com/conditional_statement_awk_command/
eg :
ls -ltrd p_390.q_50 | awk '{split($9,a,"."); split(a[1],b,"_"); if(b[2]>360) c=b[2]-360; print("z_"c"."a[2])}'
ls -ltrd p_390.q_50 | awk ' {split($9,a,"."); split(a[1],b,"_"); if(b[2]>360) {c=b[2]-360; print("mv "$9" z_"c"."a[2])} else {print ("mv "$9" "a[1]"."a[2])} }'
gives you :
mv p_390.q_50 p_30.q_50
Hutch Polecat