Need to compare numbers in alphanumeric string


 
Thread Tools Search this Thread
Top Forums UNIX for Beginners Questions & Answers Need to compare numbers in alphanumeric string
# 1  
Old 11-13-2018
Need to compare numbers in alphanumeric string

Hi,

I will be having file names like below,

Code:
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

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

Expected Output:
Code:
1420SP1.01804
1420SP1.01805D
1420SP1.01805
1420SP1.01806D
1420SP1.01806
1420SP1.01901D
1420SP1.01901
1420SP1.01902D
1420SP1.01902

TIA
# 2  
Old 11-13-2018
Try using the int builtin

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


Hope that helps
Regards
Peasant.
This User Gave Thanks to Peasant For This Post:
# 3  
Old 11-13-2018
One could also try the slightly simpler:
Code:
awk -F. '$NF + 0 < 01903' file

or:
Code:
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.
# 4  
Old 11-13-2018
Thanks a lot..Its working..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Generate a string of alphanumeric characters

Hi, I want a script of a code that will allow me to generate all possible combinations of alphanumberica characters of length 12 such that each string will contain numbers and either small or capital letters. For example a string may look like this: 123AB45cd678. (11 Replies)
Discussion started by: faizlo
11 Replies

2. UNIX for Dummies Questions & Answers

I want to compare to alphanumeric value in a unix shell script.

#!/bin/sh b= SERVER if ; then echo "hostname $a is same" ____________________________ (17 Replies)
Discussion started by: Nsharma3006
17 Replies

3. Shell Programming and Scripting

how to insert space in alphanumeric string

Hi everyone, I want help to insert space between digits and letters in a alphanumeric string. INPUT TRY234TER PHY1TYR EXPECTED OUTPUT TRY 234 TER PHY 1 TYR The lines always begin with the letters and the alphabets will be a three letter combination before and after the number. The... (2 Replies)
Discussion started by: kaav06
2 Replies

4. Shell Programming and Scripting

parse a mixed alphanumeric string from within a string

Hi, I would like to be able to parse out a substring matching a basic pattern, which is a character followed by 3 or 4 digits (for example S1234 out of a larger string). The main string would just be a filename, like Thisis__the FileName_S1234_ToParse.txt. The filename isn't fixed, but the... (2 Replies)
Discussion started by: keaneMB
2 Replies

5. Shell Programming and Scripting

ksh to compare alphanumeric values from 2 files

Hi there, I want to compare 2nd column which are alphanumeric values from each of the 2 files i.e.,lspv_pre.out and lspv_post.out , if found echo some message. lspv_pre.out hdisk0 00c39eaa451144dd rootvg active hdisk1 00c39eaa45223322 ... (3 Replies)
Discussion started by: mbak
3 Replies

6. Shell Programming and Scripting

Perl: Search for string on line then compare numbers!

Hi All, I have a file that I need to be able to find a pattern match on a line, take the number on that line check if its >0.9 or <0.1 and if this is true write the line to output.out file. An example of 4 lines in my file is: 1. driver.I177.I11.net010 1.48622200477273e-05 2.... (2 Replies)
Discussion started by: Crypto
2 Replies

7. Shell Programming and Scripting

ksh - test if string contains alphanumeric...

Okay I will let users input spaces as well :) I am having a mental block. I have done a couple of searches but havent found anything that I understand (the likes of :alpha: and awk). Basically I want to give the user an option to enter some text which will go down as a field within a flat... (3 Replies)
Discussion started by: tugger
3 Replies

8. Shell Programming and Scripting

With Regex Spliting the string into Alphanumeric and Numeric part

Hi there With shell script I'm trying to split the string into two parts. One is alphanumeric part, the other one is a numeric part. dummy_postcode_1 = 'SL1' --> res_alpha = 'SL' and res_numeric = '1' dummy_postcode_2 = 'S053' --> res_alpha = 'S' and res_numeric = '053' ... (1 Reply)
Discussion started by: ozgurgul
1 Replies

9. UNIX for Dummies Questions & Answers

AlphaNumeric String Operations

Hi :) I am writing a ksh I have a string of general format A12B3456CD78 the string is of variable length the string always ends with numbers (here it is 78.. it can be any number of digits may be 789 or just 7) before these ending numbers are alphabets (here it is CD can even be... (3 Replies)
Discussion started by: lakshmikanth
3 Replies

10. Shell Programming and Scripting

matching alphanumeric string

how to match an alphanumeric string like the following. i have to do like the following. if the input line is the data is {clock_91b} i have to replace that with the string was ("clock_91b") i tried like $line =~ s/the data is\s+\{(+)\}/the string was \(\"$1\"\)/ which... (4 Replies)
Discussion started by: sskb
4 Replies
Login or Register to Ask a Question