With awk
awk '/```/{f=!f; $0 = f ? "{>>" : "<<}"} 1'
/```/
match three backticks anywhere in the input line. You can also use$0 == "```"
to match complete line having three backticksf=!f
by default, uninitialized variables inawk
are empty in string context and zero in numeric context. Here, you'll getf=1
the first time,f=0
next time and so on$0 = f ? "{>>" : "<<}"
change the input line to desired syntax based onf
being true or false1
idiomatic way to print contents of$0
(the input record)