Concatenate a string and number and compare that with another string in awk script

I have below code inside my awk script

if ( $0 ~ /SVC IN:/ )
  {
    svc_in=substr( $0,23 , 3);
    if (msg_start == 1 && msg_end == 0)
     {
        msg_arr[msg_lnno++]=$0;
     }
  }
else if ( $0 ~ /^SVC OUT:/ )
  {
    svc_out=substr( $0, 9, 3);
      if (msg_start == 1 && msg_end == 0)
     {
        msg_arr[msg_lnno++]=$0;
     }
   }
 else if ( $0 ~ /^MSGEND/ )
  {
 if ( $svc_in$svc_out != "ABCABC" )
{
print .....
}
else
{
print ..
}
)

The issue here is it works fine when both in and out values are strings and gets an error when one of them is a number.
My input file has diff combinations, how can we convert it when we get a number in any one value?

Try:

svc_in svc_out != "ABCABC"

(do not use $'s in front of variables)

Do we need to give space in between svc_in and svc_out or without any space?

give space. otherwise it will think it's another variable.

1 Like

The space character is the concatenation operator in awk

$ echo "333" | awk '{ $0="space in front " $0 "no space after"; print $0}'
space in front 333no space after

1 Like

This worked, Thanks for your help !!

Put a string concatenation in parenthesis to better visualize the order!

if ( (svc_in svc_out) != "ABCABC" )