I need to write a script that reads through an input .txt file and replaces the end value with the end value of the next line for lines that have distance <=4000. The first label line is not actually in the input. In the below example, 3217 is the distance from the end of the first line to the start of the second line. 14021 is the distance from the previous line (not included) to the start of the first line. So once the script finds a distance <=4000, it needs to replace the end of the previous line with the end of the current line.
Any help would be greatly appreciated! Thanks!
INPUT:
chrm start end block length distance
chr7 27398704 27399096 ENm010Block536 392 14021
chr7 27402314 27402466 ENm010Block537 152 3217
chr7 27412536 27412726 ENm010Block538 190 10069
chr7 27416032 27416424 ENm010Block539 392 3305
chr7 27420022 27420972 ENm010Block540 950 3597
Desired OUTPUT:
chr7 27398704 27402466
chr7 27412536 27420972
Any help would be greatly appreciated! Thanks!
INPUT:
chrm start end block length distance
chr7 27398704 27399096 ENm010Block536 392 14021
chr7 27402314 27402466 ENm010Block537 152 3217
chr7 27412536 27412726 ENm010Block538 190 10069
chr7 27416032 27416424 ENm010Block539 392 3305
chr7 27420022 27420972 ENm010Block540 950 3597
Desired OUTPUT:
chr7 27398704 27402466
chr7 27412536 27420972