• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 821
  • Last Modified:

help write a unix script to compare and print two numeric fields

Hi,
I have a text file that contains 2 columns of numbers which are comma delimited, here is a sample
column1, column2
319290 ,319292        
319328 ,319329        
319358 ,319358
312       ,316      
319450 ,319451
I need a unix script that does the following:
1) check the length of the number in the first column if it is not equal to  6 digits put "0" instead of the missing digit like 312 in the sample above would be 312000
2) then check the length of the number in the second column number if it is not equal to 6 digits, replace the missing digit/digits with 9 so the 316 in second column would be 316999

3)compare  both the numbers in column 1 and 2 and if the number in column 2 is greater than the one in column 1  break the range and print all the numbers for example
column1, column2
319290 ,319292    
I want the script to print the whole range like this:
319290
319291
319292
finally want to put output of this in another text file called routes.

Thanks,
0
Aquamarine77
Asked:
Aquamarine77
1 Solution
 
amit_gCommented:
awk -F, '{gsub(/ /, "");} length($1) != 6 {$1 = substr($1 "000000", 1, 6);} length($2) != 6 {$2 = substr($2 "999999", 1, 6);} $2 > $1 {while ($2 >= $1) print $1++;}' YourFileName
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now