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?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

1 Answers1

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.

Freddy
  • 25,565