I have files with this kind of structure:
abc
def
ghi
...
x x y x x
x x z x x
x x y x x
...
JKL
x x y x x
x x z x x
x x y x x
...
...
*empty line*
mno
pqr
...
...
I would like to copy the whole file to a new file but with some changes. Fist, I want to affect only the lines between pattern JKL and the next empty line. On top of that, I need to replace every occurrence of the pattern y with a new pattern NEW, but only if it appears in the third column.
I tried using sed, but I got stuck at how to select columns:
sed -ne '/JKL/,/^$/s/y/NEW/'
this, of course, replaced y with NEW in all columns.
I also tried looking up awk, but I could only find examples of the two separate needs I have, and wasn't able to put them together. How could I do it?