Need to compare numbers in alphanumeric string

Hi,

I will be having file names like below,

1420SP1.01804
1420SP1.01805D
1420SP1.01805
1420SP1.01806D
1420SP1.01806
1420SP1.01901D
1420SP1.01901
1420SP1.01902D
1420SP1.01902
1420SP1.01903D
1420SP1.01903
1420SP1.01904
1420SP1.01905

From this, I need to list file names which is less than 01903(1420SP1.01903) as first half of the file name is constant. Need to compare second half by taking "." as delimeter.

Problem here is having alphanumeric.

If it's alphanumeric then it should compare only number from the string

I tried following which will work only for numbers

ls | nawk -F "." '{if($NF<01903) print $0}'

Expected Output:

1420SP1.01804
1420SP1.01805D
1420SP1.01805
1420SP1.01806D
1420SP1.01806
1420SP1.01901D
1420SP1.01901
1420SP1.01902D
1420SP1.01902

TIA

Try using the int builtin

nawk -F "." '{if(int($NF)<01903) print $0}'

Hope that helps
Regards
Peasant.

1 Like

One could also try the slightly simpler:

awk -F. '$NF + 0 < 01903' file

or:

awk -F. '$2 + 0 < 01903' file

If you want to try either of these on a Solaris/SunOS system, change awk to /usr/xpg4/bin/awk or nawk .

Thanks a lot..Its working..