awk script queries

Hi,

First query:
I am trying to execute the below command to pull all the record whose length is not of the expected. But this is not giving the expected results.

$2 is the record length passed in the script as second parameter.$filename is the filename on which the awk is executed.It is returning all the records irrespective of criteria. Please advise.

awk -v xx=$2 'length!=$xx' $filename

Second query:
In an flat file, some of the records are not of the fixed length.This is due to presence of null character and junk characters.If record length is expected to be 100..due to presence of these characters it is varying to be 102-105. when executing the awk command with length function to pull the records whose length isnt matching...for those records which have null character..the record displayed on standard output is only till null character.The subsequent fields after null character is not returned by awk.Please explain why this would happen and what is the solution to retain entire record.

Also suggest a command to identify the null characters and replace by a space or any solution to fix these junk or null characters..so that we can have a complete file whose length isnt deviating from expected length..Thanks!

Please give examples of input and output.

awk -v len=2 '{ if(NF!=len) print $0 }' awk_test 

Samples are entirely one line..as this text window doesnt accomodate many characters it shown as two lines.

First query:
By script pass : $2 = 144 ,filename=cusemp.txt

awk -v xx=144 'length!=xx' cusemp.txt >> out.txt

cat out.txt
E00200406250000000000 0001273411 0000000200406250000000000 000127341174208547600200406250000000000 0001273411INS

This is of 144 characters length.

Second query:

Due to the presence of junk characters..record size is different..this should also be of 144 characters in input..but it is not.

Input:
9LB200406250000000000 0001273409 0000000200406250000000000 0001273409^A1��166200406250000000000 0001273409INS

Output:
9LB200406250000000000 0001273409 0000000200406250000000000 0001273409

---------- Post updated at 03:41 AM ---------- Previous update was at 03:39 AM ----------

This command isnt working.I tried now..it returns records which have correct length as well..please advise.

awk -v mylen=144 '{if(length($0)!=mylen)print $0}' out.txt