This is for research. The data is power and its odd harmonics, and I am looking for a way to ID transients without having to graph everything. I just chose simple numbers so I can understand the mechanics. Thanks.
Your step 3 makes no sense to me. If y-x is not >= 100, then (y+1)-(x+1) can't be >= 100 either. This will just create an very large loop until one of the values overflows. So, until you can explain why this should be done, I'm going to ignore this requirement.
The proposal elixir_sinari makes the assumption that you are only comparing x values on odd numbered lines against y values on even numbered lines. Seeing your sample data and comments in message #6 in this thread, it looks like you want to compare the value in the 2nd column of your input file for every line except the 1st.
This slight modification to elixir_sinari's proposal:
Yes indeed! Would you mind translating into English? I don't get how it knows what x is, and I don't see where the shift to the next line happens...Thanks a ton!
I'll try. First, here is the awk script in a slightly different form:
line 1 awk '
line 2 (NR>1) && (d=$2-x)>=100{print d,NR}
line 3 {x=$2}
line 4 ' file
The line numbers in blue are to make it easy to identify what I'm talking about. They cannot appear in the script.
Line 1 says that we are using awk to perform a sequence of commands on every line of input fed into awk. The single-quotes on lines 1 and 4 contain the awk commands to be evaluated.
The file on line 4 says that input lines to be processed are to be read from a file named file .
Line 2 says that for every line read from file , if the current line number in all of the input files we've read so far is greater than 1 (NR>1) and (&&) after setting d (d=) to be the difference between the 2nd field on this line ($2) and the 2nd field on the previous line (x) it finds that d is greater than or equal to 100 (>=100) it executes the command between the braces which prints the value of d and the current line number (print d,NR).
Since there are no conditions on line 3, the command between braces will be performed on every input line. The command (x=$2) sets x to the value of the 2nd field on the current line. (Note that the commands on the 1st line weren't executed because of the condition (NR>1), but x is set as the last thing to be done on every line read by the command on line 3.)
Lines 2 and 3 are reprocessed in order for every input line read from file .
Note also that you specified (y-x)>=100; not |y-x|>=100. If you meant for the absolute value of the difference to be tested instead, you'll need to adjust the conditions on line 2 and decide if you want the actual difference to be printed or the absolute value of the difference to be printed.