0

I have output like so

v12:     "owner" : "cs1372",
v12:     "num-of-connections" : 1,
v12:     "owner" : "cq5838",
v5:     "owner" : "bb9886",
v5:     "owner" : "aq0903",
v5:     "owner" : "bj2468",
v5:     "owner" : "di3080",
v5:     "num-of-connections" : 1,

I need to return the line above the num-of-connections line. So what I want in this output is

v12:     "owner" : "cs1372",
v5:     "owner" : "di3080",

Is there an easy way to do this with sed or awk?

0
1

Using awk:

$ awk '$2=="\"num-of-connections\""{ print prev } { prev=$0 }' file
v12:     "owner" : "cs1372",
v5:     "owner" : "di3080",

Save the current record in variable prev. If the second field equals "num-of-connections", print variable prev.

Not the answer you're looking for? Browse other questions tagged or ask your own question.