Writing an AWK script, I want to store a line I find in a variable, and only later, if I also match another line, print out that original line.
Example:
a <-- save this one
b
c <-- Now that we found c, let's print a
Psudo, wish-it-worked-exactly-like-this, code:
/a/ { myvar = $0 }
/c/ { print $myvar $0 }
In dreamland produces:
ac
Actual, psychedelic, results of my wishful-thinking psudo code:
cc
Note: it's cheating to answer "just print a
, then c
as would work with a simplification of this example. The real-world use case calls for c
only being printed based on further conditions, thus the need to store the most recently seen a
on the chance a following c
will be printed.