Hi,
I'm trying this awk one-liner:
So this code prints always the previous line, of the line where the pattern /bbb/ is found.
I'm trying to make sense of it, but it seems difficult. It looks like when /bbb/ is found, x in x=$0 should be set to the record where /bbb/ is found, instead x=$0 is set to the previous record. Counterintuitive ?
Any idea why is this so ?
I'm trying this awk one-liner:
Code:
Input
aaa
bbb
ccc
awk '/bbb/{print x}{x=$0}' file
Output
aaa
So this code prints always the previous line, of the line where the pattern /bbb/ is found.
I'm trying to make sense of it, but it seems difficult. It looks like when /bbb/ is found, x in x=$0 should be set to the record where /bbb/ is found, instead x=$0 is set to the previous record. Counterintuitive ?
Any idea why is this so ?