Skip to main content
deleted 36 characters in body
Source Link
Rui F Ribeiro
  • 58k
  • 28
  • 156
  • 238

I have an output which looks like this:

ASCII file

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, but I hope this can help to answer):

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.

I have an output which looks like this:

ASCII file

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, but I hope this can help to answer):

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.

I have an output which looks like this:

ASCII file

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.

replaced the screenshot with the actual ascii file, the pseudocode now contains the line increment required
Source Link
stp30
  • 111
  • 5

I have an output which looks like this: enter image description here

ASCII file

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, but I hope this can help to answer):

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.

I have an output which looks like this: enter image description here

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, but I hope this can help to answer):

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}' 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')

I have an output which looks like this:

ASCII file

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, but I hope this can help to answer):

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.

Source Link
stp30
  • 111
  • 5

Element comparison between subsequent lines, assigning a value for each null output

I have an output which looks like this: enter image description here

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, but I hope this can help to answer):

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}' 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')