Well it taken from the “awk-exercises”.
For the input file patterns.txt, filter lines containing three or more
occurrences of “ar” and replace the last but second “ar” with “X”par car tar far Cart
part cart mart
Expected output
par car tX far Cart
pXt cart mart
awk 'BEGIN{r = @/(.*)ar((.*ar){2})/} $0~r{print gensub(r, "\1X\2", 1)}' patterns.txt
There is one think i cannot understand. What is the “@” means in BEGIN block?