trim spaces in unix for variable

HI Guys

I have written a script using awk to split a file based on some identifier and renaming the file based on two values from specific length. ts a fixed width file.

When I am trying to fetch the values

a = substr($0,11,10)
b = substr($0,21,5);

i am getting spaces in a and b values .
I have to form a file like a_b.txt but the file is forming as "a _ b .txt"

Please help guys.

To remove all the spaces in $a and $b

 
a=${a// /}
b=${b// /}

Hi when i tried using the way you provided

a = substr($0,11,10)
a1= ${a// /}

i got this error

The error context is
               a= >>> ${ <<<
awk: 0602-502 The statement cannot be correctly parsed.

To trim the spaces in your awk program from the a variable:

left spaces:

gsub(/^[ \t]+/, "", a)

right spaces:

gsub(/[ \t]+$/, "", a)

is it inside the awk ?

if it is inside the awk, use the franklin suggestion.

my data is coming as

INDIAINDIABACD      11    
INDIAINDIABACD      12    

and i split the data into multiple files based in INDIAINDIA and file name will be BACD_11.txt and BACD_12.txt but in this case it is forming as

"BACD      12   .txt" and "BACD      11   .txt"

a = substr($0,11,10)
a2=gsub(/[ \t]+$/, "", a)
b = substr($0,21,5)
b2=gsub(/[ \t]+$/, "", b)
fn = a2 "_Src" b2 ".txt"

using gusb i am not able to trim also it is returning blank to a2 and b2 respectively.

This whole code is inside awk

---------- Post updated at 07:01 AM ---------- Previous update was at 05:19 AM ----------

Thanks guys I got that solved.

Try losing the $ signs in the gsub statements.
You cannot assign gsub to a variable, it only returns the exit status
What is a sample input line?