Search a specific line for a value within a range. Unix bash script -


i'd jump specific line in file, line 33866. if third number in line within range -10 , +10 i'd print entire next line, 33867, file , stop.

if isn't should @ line 67893 (difference of +34027), if in range - print next line , stop.

this should continue, next looking @ line 101920 (difference of +34027) , on until finds value in range or reaches end of file.

now regardless of whether or not printed need repeat process @ new starting line, time new start line 33869 (difference 3), print line 33870 same file. ideally, repeat n times, n being read value input user when script ran.

please stop me right there if ask , i'll go banging head against wall , searching around net how make work on own. let me know if i'm going wrong way trying jump specific line , should search line means. input appreciated!

edit: here example of 2 lines being handled:

    17.33051021          18.02125499          30.40520932     1.776579372         -23.74037576          12.48448432 

with first number starting in column 6, second number starting in 26 , third in 46. (if minus ignored don't think matter)

reading question, guess file pretty big. assume "the 3rd number" 3rd field. come one-liner:

awk -v l=33866 -v d=34027 'nr==l&&$3>=-10&&$3<=10{p=1;next}p{print;exit}{l+=d}' file 

you need change 2 arguments (l (first line no. need check) , d (difference)).

after found right line print, awk stops processing further lines in file.

  • didn't test, if there typoes, sorry, shows idea
  • you should give example input etc. i.e. 3rd number, that? 3rd field? or aa bb 2 dfd 3 asf 555, 555?
  • another one, should show have done problem

Comments