Range generator

Dear All,
I have a sorted file like

1
2
3
8
9
10
45
46
47
78

The output will be range like

1 3
8 10
45 47
78 78

Did you have a question? Where are you stuck?

Actually, forget it. I see you are one of those persons that just posts your requirements and waits for someone else to just write your code or tell you how to do it. I don't help people like that. Someone else will probably do your work for you, but not me.

Regards,
Kevin

i am waiting for any clue. If you are not interested just forget it my friend.

Dear all,
any idea how to resolve this problem?

awk '{ if( NR == 1 ) start=$1;if(NR != 1 && $1 != (prev+1)) {print start,prev;start=$1;}prev=$1}END{print start,prev}' infile

Don't do people's homework assignments!

It is against the Unix forum policy and just encourages them to keep coming back and continue posting homework problems to be done by the very helpful and well meaning people here.

To those posting your homework, you're not learning anything by doing that. If your response is that you don't want to learn this stuff, then reconsider the career path that you are on that would require you to take courses and learn things that you inherently aren't interested in. It is a sad existence that you are setting yourself up for.

To those that help these people, consider that someday you will have to hire someone with Unix scripting experience. Would you prefer to have someone who has actually struggled with the vagaries of scripting in Unix/Linux, who asked for and learned from the help they received when they got stuck, or do you want someone who posted all their homework to some web forum so someone else could do all the work and they learned nothing. I guess what I am saying is that you are setting yourself up (or one of us) for that situation.

And it will SUCK!

Look, I know that scripting in Unix isn't easy. Programming is an inherently challenging task. Using Unix and Linux to do real work is tough. I love these forums because they are full of very helpful people working together to solve real problems in their everyday lives.

That is awesome!

But, please, use some judgement. KevinADC is right. Just looking at some of the questions that are posted here makes it easy to spot the simple homework problems.

If nothing else, help the students, but do it in a way that makes them learn. Ask them what they have tried first. Have them post their code and output. Guide them to the correct answer instead of just handing it over.

Just my 2 cent rant for the day.

Update.

saifurshaon, if I am wrong and this isn't a homework problem. I am sorry, but it looks like one of many I have seen on these boards over the years.

One way to not have something look like homework is to include as much detail as possible in the original post and then engage with the responders about any more clarifications that may be needed.

Even if it is not school work, it is still his work. Morally and ethically he should be doing it. We all need a helping hand at times, some more than others, but he obviously just wants solutions. Just look at his posting history.

Over and out.

I'm very disappointed with this thread. :frowning:

I'll close it before it gets any worse.