I have an output which looks like this:
I want to pick up the last element from the rows that contain the string "Fe\s2b". But the thing is each occurrence of "H\s\s1\s\s\s\s\s\s4861.33A" is a gridpoint and ideally I should have a "Fe\s2b" in the line next to the line containing "H\s\s1\s\s\s\s\s\s4861.33A" (they are to be alternate, in which case I can simply awk the last element for every even line).
Since this is not the case, I wish to keep an account of all the cases where the string "Fe\s2b" is searched in the next line for each "H\s\s1\s\s\s\s\s\s4861.33A" occurrence. Something like this (I know this doesn't work):
awk '{print NR, $0}' testing.txt | grep "H\s\s1\s\s\s\s\s\s4861.33A" testing.txt | awk '{
if ($1 == H && $(NF + 1)== H)
print "-99";
else
grep "Fe\s2b" testing.txt | awk "{print $NF}" testing.txt && <increment line=line+2>}' testing.txt
Here, I was trying to grab the first element of each line and compare with the first element of the next line, if they match then I assign a value '-99'; or else I awk the last element of the next line (i.e. the value corresponding to 'Fe\s2b') and jump to the n+2 line.