How to create individual entries from a range of numbers?

I want to create entries based on the series as in examples below:

Input:

2dat3 grht-5&&-15
3dat3 grht-16&&-30
4dat3 ftht-4&&-12
5sat3 ftht-16&&-20

Output:

2dat3	grht-5
2dat3	grht-6
2dat3	grht-7
2dat3	grht-8
2dat3	grht-9
2dat3	grht-10
2dat3	grht-11
2dat3	grht-12
2dat3	grht-13
2dat3	grht-14
2dat3	grht-15
3dat3	grht-16
3dat3	grht-17
3dat3	grht-18
3dat3	grht-19
3dat3	grht-20
3dat3	grht-21
3dat3	grht-22
3dat3	grht-23
3dat3	grht-24
3dat3	grht-25
3dat3	grht-26
3dat3	grht-27
3dat3	grht-28
3dat3	grht-29
3dat3	grht-30
4dat3	ftht-4
4dat3	ftht-5
4dat3	ftht-6
4dat3	ftht-7
4dat3	ftht-8
4dat3	ftht-9
4dat3	ftht-10
4dat3	ftht-11
4dat3	ftht-12
5sat3	ftht-16
5sat3	ftht-17
5sat3	ftht-18
5sat3	ftht-19
5sat3	ftht-20

So, what have you tried so far and where are you getting stuck?

It seems that you need to recognise the values you have then starting with the first value in the range, loop through displaying the required output and adding one to the counter before you go round and see if you have reached the end value.

You would also be better to say what tools you prefer to work in and your OS version (name and release level) in case there are any suggestions that rely on or could exploit the variant that you have.

Robin

I will like to use awk

Try :

this works for given input in #1

$ awk -F'[-&&]' '{for(i=$2;i<=$NF;i++)print $1"-"i}' Input
2 Likes

It worked, Thanks!

Wow! Could you explain a little please Akshay Hegde? I'd love to understand it a bit better.

Thanks,
Robin

I just used simple for loop
for(INITIALIZATION; CONDITION; AFTERTHOUGHT)

for example :

2dat3 grht-5&&-15

-&& ---> Field Separator
2dat3 grht ---> field1 $1
5 ---> Field2 $2 that is i start
15 -->last Field $NF is i end
for(i=5;i<=15;i++)print $1"-"i -->increment i till 15 and print $1 and i

1 Like

Thanks, I could see there was a loop, but the working out how it was being set up and the use of the Field Separator had me confused.

Much clearer now, but not what I would have come up with by myself. Plenty more for me to learn with awk I think! :eek:

Thanks again,
Robin