AA XXX Y1Y ZZZ GG dhz rr (AAAa) XXX Y2Y ZZZ TT GGGG UU
The input lines could vary.. only the XXX before the Y1Y and the ZZZ after Y1Y is constant (they are the neighbors of XXX and ZZZ like this). Y1Y could be anything, ex.: Y1Y, Y2Y, Y1T, etc.
Q: how can I get the OUTPUT with awk or sed or grep? (or are there any better tool for this?)
UPDATE (problem): why doesn't it works when having "." in the Y1Y?
[user@notebook ~] echo 'XXX Y1Y ZZZ' | grep -Po "(?<=XXX )(\w+)(?= ZZZ)" Y1Y [user@notebook ~] echo 'XXX Y1.Y ZZZ' | grep -Po "(?<=XXX )(\w+)(?= ZZZ)" [user@notebook ~]