Using of gsub function in AWK to replace space by underscore

I must design a UNIX script to monitor files whose size is over a threshold of 5 MB in a specific UNIX directory

I meet a problem during the for loop in my script. Some file names contain spaces.

ls -lrt | awk '$5>=5000000 && length($8)==5 {gsub(/ /,"_",$9); print};'

-rw-r--r-- 1 was61 web 19488100 Jan 17 11:13 BNP IDOCS 20110117 1058.TXT.1295262807802.239
-rw-r--r-- 1 was61 web 9187328 Jan 20 06:07 CHEQUES XP ES70.MDB.1295503676684.1665
-rw-r--r-- 1 was61 web 16968480 Jan 24 12:55 BNP IDOCS 20110124 1058.TXT.1295873751733.325
-rw-r--r-- 1 was61 web 17229240 Jan 31 12:22 BNP IDOCS 20110131 1058.TXT.1296476552934.3663
-rw-r--r-- 1 was61 web 13678240 Feb 7 14:02 BNP IDOCS 20110207 1058.TXT.1297087373504.377
-rw-r--r-- 1 was61 web 15373180 Feb 14 12:59 BNP IDOCS 20110214 1058.TXT.1297688349015.250
-rw-r--r-- 1 was61 web 15743120 Feb 21 13:03 BNP IDOCS 20110221 1058.TXT.1298293391952.390
-rw-r--r-- 1 was61 web 16881560 Feb 28 12:26 BNP IDOCS 20110228 1058.TXT.1298895983632.4110
-rw-r--r-- 1 was61 web 9494528 Mar 2 06:01 CHEQUES XP ES04.MDB.1299045692115.605
-rw-r--r-- 1 was61 web 15790820 Mar 7 13:21 BNP IDOCS 20110307 1058.TXT.1299504116925.293
-rw-r--r-- 1 was61 web 17004520 Mar 14 12:45 BNP IDOCS 20110314 1058.TXT.1300106758008.320
-rw-r--r-- 1 was61 web 18494880 Mar 21 13:22 BNP IDOCS 20110321 1058.TXT.1300713733016.415
-rw-r--r-- 1 was61 web 17444420 Mar 28 11:22 BNP IDOCS 20110328 1058.TXT.1301311351565.3013
-rw-r--r-- 1 was61 web 18307260 Apr 4 11:30 BNP IDOCS 20110404 1058.TXT.1301916643739.384
-rw-r--r-- 1 was61 web 16373820 Apr 11 12:07 BNP IDOCS 20110411 1058.TXT.1302523652962.365
-rw-r--r-- 1 was61 web 17351140 Apr 18 12:08 BNP IDOCS 20110418 1058.TXT.1303128529028.304
-rw-r--r-- 1 was61 web 6560656 May 6 11:25 IDOC20110509.1304681132500.3221
-rw-r--r-- 1 was61 web 40534016 May 13 15:30 EBW6.MDB.1305300617379
-rw-r--r-- 1 was61 web 8710871 May 26 06:47 IDOC20110526.1306392435096.870
-rw-r--r-- 1 was61 web 5061366 May 27 13:24 DRX_BNP_PRL_M_2705111400_4.TXT.1306502691153.2079
-rw-r--r-- 1 was61 web 7060706 Jun 23 13:12 IDOC20110624.1308834730309.5850
-rw-r--r-- 1 was61 web 5127367 Jun 26 06:00 CFONB160_DDA_COLLECTION.B0703480.1309068056116.8
-rw-r--r-- 1 was61 web 7766712 Jun 30 15:55 KSA050711.TXT.1309449312795.3334
-rw-r--r-- 1 was61 web 20977043 Jul 8 13:17 EXMPGSM.CSV.1310131067933.3590
-rw-r--r-- 1 was61 web 20977043 Jul 8 13:19 EXMPGSM.CSV.1310131156554.3591
-rw-r--r-- 1 was61 web 5440544 Jul 13 14:18 IDOC20110715.1310566725298.2316

When I execute ls -lrt |awk '$5>=5000000 {print $9}', file names contain spaces and are considered as different inputs in the for loop.

Unfortunately, file names are handled by external customers so I must consider it as a constraint.

To avoid such a situation, I would like to replace spaces by underscores or any other character.

In spite of my efforts, I do not succeed in replacing these spaces with gsub function in AWK.
I tried this -> ls -lrt |awk '$5>=5000000 {gsub(/ /, "_", $9); print $9}'

Unfortunately, the result of my AWK command is identical to the one without gsub function.
Just for precisions, I am on a korn shell in AIX 5.3 version.

How should I setup this gsub function in AWK ? Are ther other solutions to find a workaround to this problem ?

Thanks by advance for your feedback.

 
ls -lrt | awk '$5>=5000000 && length($8)==5 { for(i=9;i<=NF;i++){ if(i==NF) {printf("%s\n",$i);} else{printf("%s_",$i)}}}'

---------- Post updated at 01:40 PM ---------- Previous update was at 01:37 PM ----------

 
find . -type f -size 5000 -maxdepth 1

Thanks a lot, it works !